DEV Community

loading...

Discussion on: Unconditional Challenge: FizzBuzz without `if`

Collapse
kallmanation profile image
Nathan Kallman Author

Nice! I like how it uses false and true as keys on an object to select the resulting string.

If you can get rid of the || usage, then this will meet the hard mode requirements...

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