DEV Community

Discussion on: FizzBuzz for Javascript

Collapse
 
peerreynders profile image
peerreynders • Edited

Seems like an opportunity for Array.from()

const select = ([n, word]) => word || n.toString();
const make = (divisor, text) => (v) =>
  v[0] % divisor === 0 ? [v[0], v[1] + text] : v;
const fizz = make(3, 'Fizz');
const buzz = make(5, 'Buzz');
const fizzBuzz = (_v, i) => select(buzz(fizz([i + 1, ''])));
console.log(Array.from({ length: 100 }, fizzBuzz).join('\n'));
Enter fullscreen mode Exit fullscreen mode