Why is it not fulfilling all the testcases?

Tell us what’s happening:
Tell us what you need help with here.

Your code so far



function largestOfFour(arr) {
let sum=0;
let ckr;
for(let i=0;i< arr.length; i++ ){
  let tempsum=0;
  for(let j=0; j< arr[i].length; j++){
    tempsum=tempsum+arr[i][j];
  }
  if(tempsum>sum){
    sum=tempsum;
    ckr=i;
  }
}
return arr[ckr];
}

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

Challenge: Return Largest Numbers in Arrays

Please stop editing the auto-generated posts to remove information. The link to the challenge you are working on is important. The description of what you need help with is important.

I think maybe there might be a misunderstanding about what this function should be returning. The arrary (arr) passed into the function has four subarrays in it. Each of those subarrays has four numbers in it. You want to go through each of the subarrays and find the largest number. You will create a new array consisting of the largest number for each of the four subarrays. Since there are four subarrays then the array you return will have four numbers (one for each subarray). Does that make sense?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function largestOfFour(arr) {
let arr1 = [];
for(let i=0; i< arr.length; i++){
  let grt=0;
  for(let j=0; j< arr[i].length; j++){
    if(arr[i][j]>grt)
    grt=arr[i][i];
  }
  arr1.push(grt);
}
return arr1;
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

Please describe what is happening in your own words. It is much easier to understand what your problem is when you interact with us.


Why are you initializing grt to 0? What if your array has all negative numbers?