DEV Community

Discussion on: [Challenge] 🐝 FizzBuzz without if/else

Collapse
 
rad_val_ profile image
Valentin Radu

Here's the simplest I can think of without any statements. 🙃

function run(n, i=1, j=1, k=1, acc=[]) {
  !j && k && acc.push('fizz')
  !k && j && acc.push('buzz')
  !k && !j && acc.push('fizzbuzz')
  k && j && acc.push(i)

    n - 1 && run(n - 1, i + 1, (j + 1) % 3, (k + 1) % 5, acc)
  return acc
}

console.log(run(30))
Collapse
 
nombrekeff profile image
Keff

Nice, recursion for the win 💪

Collapse
 
nombrekeff profile image
Keff

Thanks for sharing!