JavaScript finding the largest integer in an array of arrays

后端 未结 5 422
独厮守ぢ
独厮守ぢ 2021-01-23 21:30
function largestOfFour(arr) {
    var newArray = [];
    for(var i =0; i <=arr.length-1; i++){
        console.log(arr[i]);
        newArray[i] = Math.max(arr[i]);
           


        
5条回答
  •  孤城傲影
    2021-01-23 22:03

    If you want the ultimate max do this.

    var original = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];
    Math.max.apply(null, original.map(function(arr) { return Math.max.apply(null, arr); }));
    

    or if you want a the max of each array just do

    original.map(function(arr) { return Math.max.apply(null, arr); });
    

提交回复
热议问题