top | item 35525577

(no title)

dontchooseanick | 2 years ago

Commenting on the last exercise, "loops" on https://javascript.sumankunwar.com.np/

The average functional programmer writes this - and not a for loop :

    ````
    const fizzbuzz = (n)=>(n%15==0)?"FizzBuzz":(n%5==0)?"Buzz":(n%3==0)?"Fizz":n;
    Array(101).fill(0).map((_,i)=>fizzbuzz(i)) 
    ````

discuss

order

LordDragonfang|2 years ago

   Array(101).fill(0).map((_,i)=> [...])
It's astonishing to me that even with all the niceties added to ES7+, JS still needs to resort to a hack like this for a simple range generator. At least give iterators support for forEach(), reduce(), and map(), so we can use `Array(100).keys()` without having to wrap it with the spread operator.

Also, can't help but snark that apparently the "average" FP is so preoccupied with showing off their one-liners that they fail the problem requirements (should be `Array(100).fill(0).forEach((_,i)=>console.log(fizzbuzz(i+1)))`).

graftak|2 years ago

A little bit better: Array.from({ length: 100 }, () => ...)

boringuser2|2 years ago

Actual developers just use lodash.

Honestly, I don't understand the complaint, a lean stdlib isn't a shortcoming.

metalliqaz|2 years ago

I don't think that was the intention of the exercise.