Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Last active June 19, 2017 23:58
Show Gist options
  • Save Woodsphreaker/33248d8ba5a0c3352dcf917bb23a9610 to your computer and use it in GitHub Desktop.
Save Woodsphreaker/33248d8ba5a0c3352dcf917bb23a9610 to your computer and use it in GitHub Desktop.
Fizzbuzz
const generateListOfNumbers = (toMax = 50) => [...Array(toMax + 1).keys()].slice(1)
const isDivisibleBy = (number) => {
    return {
        "3" : "fizz",
        "5" : "buzz",
        "15": "fizzbuzz"
    }[number]
}
const testDivisionBy = (x, y) => x % y === 0
const testCondition = (x) => {
    if (testDivisionBy(x, 15)) return isDivisibleBy("15")
    if (testDivisionBy(x, 5)) return isDivisibleBy("5")
    if (testDivisionBy(x, 3)) return isDivisibleBy("3")
    return x
}
const listOfNumbers = generateListOfNumbers(100)
const solution = listOfNumbers.map(testCondition).join(',')
console.log(solution)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment