3 ms·
I like that example. Since I'm preaching to prefer functional style programing and to separate the side effect from the rest of the algorithm, I'd write the cod
by blumomo 7y ago
I like that example. Since I'm preaching to prefer functional style programing and to separate the side effect from the rest of the algorithm, I'd write the code this way:
Array
.from({length: 100}, (v, k) => k+1)
.map(i => {
if (i % 3 == 0 && i % 5 == 0) return "FizzBuzz"
if (i % 3 == 0) return "Fizz"
if (i % 5 == 0) return "Buzz"
return i
})
.forEach(console.log)