DEV Community

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

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