How can I easily obtain the min or max element of a JavaScript Array?
Example Psuedocode:
let array = [100, 0, 50] array.min() //=> 0 array.max()
For big arrays (~10⁷ elements), Math.min and Math.max procuces a RangeError (Maximum call stack size exceeded) in node.js.
Math.min
Math.max
For big arrays, a quick & dirty solution is:
Array.prototype.min = function() { var r = this[0]; this.forEach(function(v,i,a){if (v