📜  返回数组中的最大数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:12.084000             🧑  作者: Mango

代码示例2
// Return Largest Numbers in Arrays

function largestOfFour(arr) {
    let largestArr = [];
    for (let i = 0; i < arr.length; i++) {
        largestArr.push(Math.max(...arr[i]));
    }
    return largestArr;
}

largestOfFour([
    [4, 5, 1, 3],
    [13, 27, 18, 26],
    [32, 35, 37, 39],
    [1000, 1001, 857, 1],
]);

// OR

function largestOfFour(arr) {
    return arr.map(function (group) {
        return group.reduce(function (prev, current) {
            return current > prev ? current : prev;
        });
    });
}