DEV Community

Discussion on: JS Coding Question #7: Classic Fizz Buzz (one-liner 🤯)

frontendengineer profile image
Let's Code Author • Edited on

Nice and thanks for sharing! These one-liner are nice and amazing to see but not worth to spend much time and energy on as one will not present them on an actual interview.

If I go on an interview and get asked to code Fizz Buzz, i would still stick to the old if-else solution. Do you feel the same?

lukeshiru profile image

tbh, it's been years since I got something like this on an interview (that's why when I do the interviews I don't do this kind of exercises), but my solution on an interview would be something like:

const fizzBuzz = n =>
    [...Array(n + 1).keys()].map(
        index =>
            `${++index % 3 ? "" : "Fizz"}${index % 5 ? "" : "Buzz"}` || index
Enter fullscreen mode Exit fullscreen mode

Mainly because I haven't used a for in years now, so doing it for an interview wouldn't make much sense for me.

Thread Thread
frontendengineer profile image
Let's Code Author

looks good to me! thanks for sharing.

i hardly use old school for iterate as well especially there are other better alternatives.

Some comments have been hidden by the post's author - find out more