FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.

Home Page:https://fcc.asia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

哪里错了

VulnerableGroups opened this issue · comments

Challenge Return Largest Numbers in Arrays has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function largestOfFour(arr) {
  // 请把你的代码写在这里
  var array=[];
  //遍历数组
  var max=0;
  for(var i=0;i<arr.length;i++){
    for(var j=0;j<arr[i].length;j++){
      if(max<arr[i][j]){
        max=arr[i][j];
      }
    }
    array.push(max);
    
  }
  return array;
}

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

@VulnerableGroups array.push(max) 之后要给 max 重新赋值。
现在的代码,你在第一组里找到了 27。到了第二组,max 还是 27,第二组里面又没有比 27 小的,所以就又 push 了一次 27