Hello,
I have a tendency of copying the challanges into VS code and solve them there, seeing errors in the console that shows line number helps alot.
However, below code seems to work in the VS code, i tried all four test cases and the function returns correct results, however it doesnt pass the tests – result
is not defined,
why?
thanks in advance and Merry Chistmas Everyone
Your code so far
function largestOfFour(arr) {
// You can do this!
for ( let i =0; i < arr.length; i++) {
let highestNum = -99999;
let result = [];
//console.log(arr[i]);
for (let j = 0; j < arr[i].length; j++) {
//console.log(arr[i][j])
if (arr[i][j] > highestNum) {
highestNum = arr[i][j];
}
} //console.log(highestNum)
result.push(highestNum)
highestNum = -99999;
//console.log(result)
return console.log(result)
}
}
console.log(result);
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 (Macintosh; Intel Mac OS X 10.13; rv:64.0) Gecko/20100101 Firefox/64.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays