Skip to content

Instantly share code, notes, and snippets.

@ecancino
Created May 10, 2017 15:57
Show Gist options
  • Select an option

  • Save ecancino/4ef98606b358fbacc90ebf998210983c to your computer and use it in GitHub Desktop.

Select an option

Save ecancino/4ef98606b358fbacc90ebf998210983c to your computer and use it in GitHub Desktop.
Fizzbuzz
const range = length => [...Array(length).keys()];
const divBy = n => v => (v % n === 0)
const divBy3 = divBy(3);
const divBy5 = divBy(5);
const all = (n, xs) => xs.reduce((p, c) => p && c(n), true);
const divBy15 = n => all(n, [ divBy3, divBy5 ]);
const fizbuzz = n => range(n)
.map(n =>
divBy15(n) ? `FizzBuzz (${n})` :
divBy3(n) ? `Fizz (${n})` :
divBy5(n) ? `Buzz (${n})` : n);
const fb = fizbuzz(100);
console.log(fb.join(', \n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment