DEV Community

loading...

Discussion on: Unconditional Challenge: FizzBuzz without `if`

Collapse
jpantunes profile image
JP Antunes • Edited

Well Mr. Henney has a great answer:

const fizzBuzz = n => {
  const test = (d, s, x) => n % d == 0 ? _ => s + x('') : x;
  const fizz = x => test(3, 'Fizz', x);
  const buzz = x => test(5, 'Buzz', x);

  return fizz(buzz(x => x))(n.toString());
}

edit: but it still has a conditional...

Forem Open with the Forem app