Tell us what’s happening:
here I have a program that splices away the smallest number in the subarray, leaving only the biggest number.
when I console.log the examples, I was able to achieve the results, but still wouldn’t pass the test.
Your code so far
function largestOfFour(arr) {
// You can do this!
for (let i =0; i < arr.length; i++) {
while (arr[i].length != 1) {
if (arr[i][0] >= arr[i][1]) {
arr[i].splice(1,1);
} else {
arr[i].splice(0,1);
}
}
}
return arr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
I thought maybe its still in a nested array like [[4,27,39, 1001]]
so I tried
arr = arr[0].splice(0,4)
and
arr = [...arr[0]]
both didn’t work
what am I doing wrong here?
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays