Javascript 为什么我的负数函数不起作用 函数最大四(arr){ 设maxOfech=[]; for(设i=0;i

Javascript 为什么我的负数函数不起作用 函数最大四(arr){ 设maxOfech=[]; for(设i=0;i,javascript,Javascript,这是代码问题是关于负数的 当我在数组中放入负数时,数组工作不正常,显示的是1而不是-22 但是,当我用正数做同样的事情时,所有的都可以 请帮我找出代码中的错误。函数最大四(arr){ function largestOfFour(arr) { let maxOfEach = []; for (let i = 0 ; i < arr.length ; i ++){ let tempx = [i][0]; for (let j = 1 ; j <

这是代码问题是关于负数的 当我在数组中放入负数时,数组工作不正常,显示的是1而不是-22 但是,当我用正数做同样的事情时,所有的都可以 请帮我找出代码中的错误。

函数最大四(arr){
function largestOfFour(arr) {
  let maxOfEach = [];
  for (let i = 0 ; i < arr.length ; i ++){
          let tempx = [i][0];
      for (let j = 1 ; j < arr[i].length ; j++){
          if (arr[i][j] > tempx){
            tempx = arr[i][j]
          }
      }
      maxOfEach.push(tempx);
  }
  // You can do this!
  return maxOfEach;
}
let x= 
largestOfFour([[4, 5, 1, 3], [-2222, -22, -222, -2222], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(x);
设maxOfech=[]; for(设i=0;itempx){ tempx=arr[i][j] } } 每个推力的最大值(tempx); } //你能做到! 返回maxOfech; } 设x= 最大的四个([[4,5,1,3],-2222,-22,-222,-2222],[32,35,37,39],[10001001857,1]); 控制台日志(x);

设tempx=arr[i][0];问题是,在我让tempx=[i][0]之前

这是什么?你自己问题的解决方案是什么?如果是,请记录并说明为什么您的答案解决了您的问题
let tempx=[i][0]
这看起来像是有人把
设为tempx=i编码到模糊器中。您是否打算让tempx=arr[i][0]?它看起来也解释了你的错误。哦,谢谢,是的,你是对的
function largestOfFour(arr) {
  let maxOfEach = [];
  for (let i = 0 ; i < arr.length ; i ++){
          let tempx = arr[i][0];
      for (let j = 1 ; j < arr[i].length ; j++){
          if (arr[i][j] > tempx){
            tempx = arr[i][j]
          }
      }
      maxOfEach.push(tempx);
  }
  // You can do this!
  return maxOfEach;
}
let x= 
largestOfFour([[4, 5, 1, 3], [-2222, -22, -222, -2222], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(x);