What Is The Most Efficient Way To Get The Highest And The Lowest Values In A Array
is there something like PHP: max() in javascript? lets say i have an array like this: [2, 3, 23, 2, 2345, 4, 86, 8, 231, 75] and i want to return the highest and the lowest value
Solution 1:
Applying the Math.max
and Math.min
built-in methods can be really fast:
var array = [2, 3, 23, 2, 2345, 4, 86, 8, 231, 75];
var max = Math.max.apply(Math, array); // 2345
var min = Math.min.apply(Math, array); // 2
Post a Comment for "What Is The Most Efficient Way To Get The Highest And The Lowest Values In A Array"