I\'m trying to find a method to find the max value comparing multiple(unknown number, but same length) arrays for each observation in the arrays, returning an array with the max
var data = [
[2.2, 3.3, 1.3],
[1.2, 5.3, 2.2],
[0.3, 2.2, 5.2]
];
function maxAtIndex (data) {
//output
var maxArray = [];
//loop arrays passed in
for (var i = 0; i < data[0].length; i++) {
var possibleValues = [];
//get value in array at index
for (var j = 0; j < data.length; j++) {
possibleValues.push(data[j][i]);
}
//get the highest from possible values
var highest = Math.max.apply(null, possibleValues);
//store in output array
maxArray.push(highest);
}
return maxArray;
};
console.log(maxAtIndex(data)); //[ 2.2, 5.3, 5.2 ]