Skip to content

Instantly share code, notes, and snippets.

@ulisesantana
Last active May 12, 2018 11:21
Show Gist options
  • Save ulisesantana/d5563cd11f0c925e4d0fe9ea9e26ff19 to your computer and use it in GitHub Desktop.
Save ulisesantana/d5563cd11f0c925e4d0fe9ea9e26ff19 to your computer and use it in GitHub Desktop.
Fizz Buzz JavaScript Solution
function fizzBuzz(num) {
const isDivisibleBy = x => y => y % x === 0;
const isDivisibleBy3 = isDivisibleBy(3);
const isDivisibleBy5 = isDivisibleBy(5);
return isDivisibleBy3(num) && isDivisibleBy5(num)
? 'FizzBuzz'
: isDivisibleBy3(num)
? 'Fizz'
: isDivisibleBy5(num)
? 'Buzz'
: num;
}
Array.apply(null,new Array(100)).map((value, index) => {
console.log(fizzBuzz(++index))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment