Code Monkey home page Code Monkey logo

foobarqix's Introduction

FooBarQix Kata

Usage

  • Clone this repository and run npm install
  • Run tests with npm run test or npm t

Instructions

Write an app that takes one number as input and returns a string as output:

fooBarQix.compute(1);
// returns "1"

However, if the number follows one of the rules below, then return a word instead. For example, numbers that are divisible by 3 but do not contain 3 return "Foo":

fooBarQix.compute(6);
// returns "Foo"

Write your app following the TDD development lifecycle to ensure good code quality. Your app is considered completed once it has implemented all the rules stated below.

Rules

  • If the number is divisible by 3 or contains 3, return "Foo" instead of 3

    fooBarQix.compute(6)
    // returns "Foo" as 6 is divisible by 3
    
    fooBarQix.compute(13)
    // returns "Foo" as 13 contains 3
  • If the number is divisible by 5 or contains 5, return "Bar" instead of 5

    fooBarQix.compute(10)
    // returns "Bar" as 10 is divisible by 5
  • If the number is divisible by 7 or contains 7, return "Qix" instead of 7

    fooBarQix.compute(14)
    // returns "Qix" as 14 is divisible by 7
    
    fooBarQix.compute(17)
    // returns "Qix" as 17 contains 7
  • More than one rule can apply at the same time

    fooBarQix.compute(15)
    // returns "FooBarBar" as 15 is divisible by 3, is divisible by 5, and contains 5
  • Prioritize the "divisor" rule over the "contains" rule

    fooBarQix.compute(51)
    // returns "FooBar" as 51 is divisible by 3 and contains 5

Recommended Order of Tests

Remember that when practicing TDD, you should always start with the simplest test first. Here is a list of tests I recommend that you start with:

  1. Return "1" when the input is 1
  2. Return "Foo" when the input is divisible by 3 but does not contain 3 (i.e. input is 6)
  3. Return "Bar" when the input is divisible by 5 but does not contain 5 (i.e. input is 10)
  4. Return "Qix" when the input is divisible by 7 but does not contain 7 (i.e. input is 14)
  5. Return "FooBar" when the input is divisible by 3 and 5 but does not contain either number (i.e. input is 60)
  6. Return "FooQix" when the input is divisible by 3 and 7 but does not contain either number (i.e. input is 21)
  7. Return "BarQix" when the input is divisible by 5 and 7 but does not contain either number (i.e. input is 140)

You should be able to figure out the rest of the tests on your own!

foobarqix's People

Contributors

angrylobster avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.