Skip to content

Instantly share code, notes, and snippets.

@knicklabs
Last active February 13, 2017 03:56
Show Gist options
  • Select an option

  • Save knicklabs/9ad3f496583b73fab2785b510f3fef04 to your computer and use it in GitHub Desktop.

Select an option

Save knicklabs/9ad3f496583b73fab2785b510f3fef04 to your computer and use it in GitHub Desktop.
Fun FizzBuzz Solution
const maybe = (result) => {
return {
if(number) {
return {
divisibleBy(divisor) {
return number % divisor === 0 && result;
}
}
}
}
}
const result = (Array.from({length: 100})).map((_, index) => {
const number = index + 1
return maybe('FizzBuzz').if(number).divisibleBy(15)
||
maybe('Buzz').if(number).divisibleBy(5)
||
maybe('Fizz').if(number).divisibleBy(3)
||
number
}).join('\n')
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment