JavaScript finding the largest integer in an array of arrays

后端 未结 5 423
独厮守ぢ
独厮守ぢ 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

    It won't work like that. Math.max expect separate numbers. You can get desired output using apply

    function largestOfFour(arr) {
        return arr.map(function(subArr){
            return Math.max.apply(Math, subArr);
        });
    }
    

提交回复
热议问题