I have an array of arrays, each one of them consists of two values - timestamp and price.
[
[1147651200000, 376.2],
[1147737600000, 350],
[1147824000000, 374.5]
]
I need to find date and time in which price was the lowest among all points. What function should I use, pls help.
EDIT:
Thanks everyone! I took tests to to see which function is fastest. Here is how I did it (example with .sort, others are same)
console.time('cycle');
var k = 0;
while (k<10000) {
var input = [
[1147651200000, 376.2],
[1147737600000, 350],
[1147824000000, 374.5]
];
var output = input.sort(function(a,b){
return a[1] > b[1];
})[0];
k++;
}
console.log(output);
console.timeEnd('cycle'); //36 ms
.map //67 ms
minimum in cycle // 108 ms
.sortwith a custom callback to sort by the price value, then get the first element of the resulting array. This will be the one with the lowest price.var min = _.min( input_array, function(n){ return n[1]; });