There was a similar and equally really good thread about a month ago that had some devilishly clever solutions... highly recommend it!
My contributions below:
//1constfizzBuzz=n=>{constmapper=(arr,modulo,txt)=>arr.filter(e=>e%modulo==0).forEach(e=>arr[arr.indexOf(e)]=txt);letx=1;constrange=[...Array(n)].map(_=>x++)mapper(range,15,'FizzBuzz');mapper(range,5,'Buzz');mapper(range,3,'Fizz');returnrange.toString();}//2constfizzBuzz=n=>{letx=1;constrange=[...Array(n)].map(_=>x++);for(leti=2;i<=n;i+=3)range[i]='Fizz';for(leti=4;i<=n;i+=5)range[i]='Buzz';for(leti=14;i<=n;i+=15)range[i]='FizzBuzz';returnrange.toString();}//3constfizzBuzz=n=>{constisFizzBuzz=n=>({false:'',true:'Fizz'}[n%3==0]+{false:'',true:'Buzz'}[n%5==0]||n.toString());letx=1;return[...Array(n)].map(_=>isFizzBuzz(x++)).toString();}//4 ...originally from a Kevlin Henney presentation here: https://youtu.be/FyCYva9DhsI?t=1191constfizzBuzz=n=>{consttest=(d,s,x)=>n%d==0?_=>s+x(''):x;constfizz=x=>test(3,'Fizz',x);constbuzz=x=>test(5,'Buzz',x);returnfizz(buzz(x=>x))(n.toString());}
There was a similar and equally really good thread about a month ago that had some devilishly clever solutions... highly recommend it!
My contributions below:
Nice stuff. I will be checking out the thread!
There have been some really clever solutions posted here as well.