4 ms·
It's bad and overused. Example: the top SO answers for "find max of an array" suggest using spread [1]: Math.max(...array) but this runs into implementat
by ridiculous_fish 4y ago
It's bad and overused.
Example: the top SO answers for "find max of an array" suggest using spread [1]:
Math.max(...array)
but this runs into implementation-defined limits on the number of arguments you can pass to a function, which is often as low as 65k; now your function is needlessly limited and works differently across browsers.
1: https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript https://stackoverflow.com/questions/1669190/find-the-min-max... and https://stackoverflow.com/questions/45123468/max-of-array-in-javascript https://stackoverflow.com/questions/45123468/max-of-array-in...
- culi 4y agois `.reduce` the preferred method then?
- zeroonetwothree 4y agoYou could use `reduce` but it's a lot slower than a normal loop. And if your array is tiny (such that perf doesn't matter) you can just do the spread operator, so there's no real reason to ever use it.
- deleted 4y ago[deleted]