Why does exercise think my code is incorrect?

Tell us what’s happening:
So I am pretty sure I got my algorithm correct however, the exercise returns an error for some of its test cases when I try to submit it.

I’ve been using playcode.io to practice from scratch and the console seems to return what the exercise is looking for in every case.

Knowing that my code was correct, I decided to look up the solution and when I copied/pasted the websites’ solution into playcode.io, it returns a completely different answer than what the exercise is looking for…

Now I am really confused as to why and how two separate editors that are for the same language have different syntax… or at the very least… one editor assumes the other is incorrect.
I think my code was foolproof not just because playcode editor said so, but also, in the bootcamp editor, I even checked my work by using console.log(arr) towards the very end of my function and the console displays the exact answers that this exercise was looking for.

Suffice to say, based on the syntax I have covered so far from this bootcamp, I thought I was certain and yet, the bootcamp testers seem to betray its own curriculum.
if someone can explain why playcode editor and even the exercise itself displays the correct answer while the submission link is telling me I am wrong I would greatly appreciate it.

Also… one thing I noticed was that for my second loop:

for(let j=0; j<=arr[i].length; j++)
the condition should be length-1 however, my code does not work unless the length condition is equal to the actual length of the array which is odd because when I wrote out each loop manually, each subarray will be reduced to the largest number in length-1 times. but my code will not work for certain cases unless it has one extra loop.

Your code so far

let b23 = [[223, 222, 244, 123], [-72, -3, -17, -10], [25, 48, 21, -3]];

function tester(arr){
  for(let i=0; i<=arr.length-1; i++){
    let a2 = arr[i];
    
    for(let j=0; j<=arr[i].length; j++){
      
      let beg = a2[0];
      let ender = a2.length-1;
      
      let end = a2[ender];
      
      if(beg > end){
        let endIndex = a2.indexOf(end);
        a2.splice(endIndex, 1);
        
      }
      else if(end > beg){
        a2.splice(0, 1);
      }
      
    }
    arr[i] = a2.toString();
    
  }
  console.log(arr)
}

tester(b23);


function largestOfFour(arr) {
  // You can do this!
  let result = [];

  for(let i=0; i<=arr.length-1; i++){
    let largestNum = arr[i][0];

    for(let j=1; j<=arr[i].length; j++){
      if(arr[i][j] > largestNum){
        largestNum = arr[i][j];
      }
    }
    result[i] = largestNum;


  }
  return result;
}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:

Your largestOfFour solution passes all tests and works fine in both editors for me here on Chromium Version 74.0.3729.169.

.length doesn’t cause an error, but it means you’re comparing to an undefined value. .length-1 is correct and again, works correctly here. There seems to be some problem on your end with the FCC site. Try another browser?

Also, FCC has a bug that i don’t know if have been entirely fixed but the solution was to logout clear cache and re login again and type in the answer again and it should work =)

For the first code block which I’m guessing is your code.

  1. You are converting to Strings, you should not do that.

  2. If you change the last assignment

arr[i] = a2.toString();

to use bracket notation and assign the value of the element inside the a2 array to arr[i] you will pass the test.

arr[i] = a2[0];

  1. You will have to return the array (where you have your console.log()).
  1. The reason i convereted to String is because it was a nested array… it was looking for just one array therefore

  2. if I used bracket notation it would fail because it would have 3 different arrays inside an array