I still like the first solution you have provided only change I would do is remove the math reminder operation out of the if loop like below (this improves performance by 3x)
function fizzBuzz(n) {
let x = 0;
let y = 0;
for (let i = 1; i <= 100; i++) {
var result = "";
x = i%3;
y = i%5;
if (x === 0 && y === 0) result += "fizzbuzz";
else if (x === 0) result += "fizz";
else if (y === 0) result += "buzz";
console.log(result || i);
}
}
fizzBuzz(15);
even though the one-liner is fancy it's very complicated to understand and its really slow.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I still like the first solution you have provided only change I would do is remove the math reminder operation out of the if loop like below (this improves performance by 3x)
even though the one-liner is fancy it's very complicated to understand and its really slow.