DEV Community

Discussion on: Solving the FizzBuzz Interview Question with JavaScript

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Here are some more (I omitted the console logging though, these are just the basic solving function):

const fizzbuzz = x=>[x,f='fizz',b='buzz',f+b][!(x%3)|!(x%5)<<1]
Enter fullscreen mode Exit fullscreen mode

and:

const fizzBuzz = x=>({1:x,6:f="fizz",10:b="buzz",0:f+b}[x**4%15])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
therickedge profile image
Rithik Samanthula

Yeah, that's awesome

Collapse
 
dannyengelman profile image
Danny Engelman

But unreadable and not easy to extend

let FB = Array(100)
  .fill((x, div, label) => x % div ? "" : label)
  .map((func, idx) =>
    func(++idx, 3, "Fizz") + func(idx, 5, "Buzz") || idx
  );
Enter fullscreen mode Exit fullscreen mode


`