DEV Community is a community of 642,931 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Discussion on: Unconditional Challenge: FizzBuzz without `if`

JP Antunes

Does this one count for the hard mode?

``````const fizzBuzz = n => {
const mapper = (arr, modulo, txt) => arr
.filter(e => e % modulo == 0)
.forEach(e => arr[arr.indexOf(e)] = txt);
let x = 1;
const range = [...Array(n)].map(_ => x++)

mapper(range, 15, 'FizzBuzz');
mapper(range, 5, 'Buzz');
mapper(range, 3, 'Fizz');

return range.toString();
}
``````
Nathan Kallman

Nice solution! For hard mode, I think either do it without `.filter` or show how `.filter` could be implemented according to the rules.

JP Antunes

``````const fizzBuzz = n => {
let x = 1;
const range = [...Array(n)].map(_ => x++);
for (let i = 2; i <= n; i += 3) range[i] = 'Fizz';
for (let i = 4; i <= n; i += 5) range[i] = 'Buzz';
for (let i = 14; i <= n; i += 15) range[i] = 'FizzBuzz';
return range.toString();
}
``````
Nice! I'll accept it even though I said no `for` loops because I like that you used the stepping statement to simply go through the multiples of 3,5,15. That's creative!
I was more expecting someone to abuse the `i <= n` into the `n % 3` type of check in a traditional fizz buzz. (especially abusing `while(n % 3)` into a more convoluted `if`)