DEV Community

Discussion on: Recursive FizzBuzz in JavaScript

Collapse
 
jonrandy profile image
Jon Randy 🎖️
console.log([...Array(100)].map((e,i)=>(++i%3?'':'fizz')+(i%5?'':'buzz')||i).join("\n"))
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sabbin profile image
Sabin Pandelovitch • Edited

Another approach if you want to create an array is using the Array.from() method. This way you can combine the spread operator and the map together in one operation.

Array.from(
  { length: 100 },
  (o, i) => `${++i % 3 ? "" : "Fizz"}${i % 5 ? "" : "Buzz"}` || i
).forEach((el) => console.log(el));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jonrandy profile image
Jon Randy 🎖️

Needs fixing for "FizzBuzz"

Thread Thread
 
sabbin profile image
Sabin Pandelovitch

Indeed! I fixed the code in the comment. Didn't pay too much attention to the description