Javascript 返回数组中的最大数,我做错了什么?
返回由每个提供的子数组中的最大数组成的数组。为简单起见,提供的数组将正好包含4个子数组Javascript 返回数组中的最大数,我做错了什么?,javascript,arrays,algorithm,numbers,Javascript,Arrays,Algorithm,Numbers,返回由每个提供的子数组中的最大数组成的数组。为简单起见,提供的数组将正好包含4个子数组 function largestOfFour(arr) { let numArr = []; for(let i = 0; i < arr.length; i++){ let num = Math.max(...arr[i]); numArr.push(num); } return Math.max(...numArr); } largestOfFour([[4, 5, 1,
function largestOfFour(arr) {
let numArr = [];
for(let i = 0; i < arr.length; i++){
let num = Math.max(...arr[i]);
numArr.push(num);
}
return Math.max(...numArr);
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
函数最大四(arr){
设numArr=[];
for(设i=0;i
您只需在末尾返回numArr
,而无需再次调用它:
函数最大四(arr){
设numArr=[];
for(设i=0;i log(最大的四个([4,5,1,3],[13,27,18,26],[32,35,37,39],[10001001857,1])代码>返回由每个提供的子数组中的最大数组成的数组。因此,只需返回numArr
,而不是在末尾调用Math.max
,非常感谢!!!我不知道为什么我以后又用了Math.max()。。我也喜欢你的map()方法!!!