Hacker News new | ask | show | jobs
by dontchooseanick 1162 days 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)) 
    ````
3 comments

   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)))`).

A little bit better: Array.from({ length: 100 }, () => ...)
Indeed, much cleaner to do `Array.from({length: 100}, (_,i) => fizzbuzz(i));`
While we're cleaning it up:

   fizzbuzz = i => (i % 3 ? "" : "Fizz") + (i % 5 ? "" : "Buzz") || i
   Array.from({length: 100}, (_,i) => console.log(fizzbuzz(i+1)))
Actual developers just use lodash.

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

...It absolutely is a shortcoming. Python is the second-most popular language out there, despite its awful performance, largely because of its comprehensive stdlib. (First is JS, because web).

And I don't understand how you can't see the irony of praising a "lean" stdlib immediately after saying every "actual" developer has to add the bloat of importing lodash.

Again, a lean stdlib is a feature, not a bug.

You can have theoretical disagreements with this, but you didn't invent the most popular programming in the world.

As for Python, not interested, it's mostly a "performance doesn't matter, being able to do this without expertise, time or even necessarily intellect does" niche.

JS has been slow to roll in core functionality, but is has made great strides by being highly conservative, not generating the kind of bloat that PHP has.

>you didn't invent the most popular programming in the world.

This is such a weird ad hominin (especially from a two-week-old account).

Regardless, the absolute, overwhelming popularity of jquery pre-ES6 goes to show that practically every developer was of the opinion that JS's weak stdlib was a bug, and the community did their best to patch it. ES7+ is leagues better for it, but it still has room for improvement.

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