3 ms·
Funnily enough, that variable arity is mentioned in the article as a nuisance: > ... wincing slightly at the lambda notation you need to avoid running afoul of
by creata 5y ago
Funnily enough, that variable arity is mentioned in the article as a nuisance:
> ... wincing slightly at the lambda notation you need to avoid running afoul of JavaScript’s variadic Math.max()...
- goto11 5y agoIt is a typical language-comparison strawman. He is writing list.reduce((x,y)=>Math.max(x,y)) To get the max number in a list. And he is "winching" because he can't write: list.reduce(Math.max) Because the variable arity of max does not play well with reduce. But because of the variable arity he can write: Math.max(...list) Which is even simpler. So he deliberately writes overly complex JavaScript code to show how the other language is more concise.
- LAC-Tech 5y agoIIRC the spread syntax only works with relatively small arrays, because it's function application at the end of the day. So worthwhile keeping in mind that the nice JS code falls apart.
- goto11 5y agoFair point. In any case, if you wanted to do more than trivial array processing in JS, you would use a library like lodash which have an array max function. And if you think lodash is still to verbose, you can define your own: const å = list => list.reduce((x,y) => Math.max(x, y)); Now you can write å(list) to get the max value of an array!
- LAC-Tech 5y agowell yeah I could also write a function in C that does that. I don't think that's the point.