I know there is Math.max(), reduce(), and even for loop:
var array = [1 , 2 , 3 , 6 , 12 , 13 , 17 , 3];
var biggest = 0;
for (var i = 0; i < array.length; i++)
{
if(biggest < array[i])
{
biggest = array[i];
}
}
console.log(biggest);
But I need to get EVERY highest element from the object/array. For example I have few measurements:
var object = {m1 : 100 , m2 : 200, m3: 150, m4 : 200, m5 : 100};
So I need to get info from this object that m2 and m4 has the highest values and the value is 200.
The idea is I copy the object (original must be saved for further inspections), get the highest value - save it, remove it from object. I try to find all the rest key:value pairs that has the highest score, by removing every from the object till the object has no more value of 200 (in this example).
Is this a good approach? Maybe I can do something better, or maybe there are some build in JS features that are fastest with better synthetic?