Tell us what’s happening:
There is an issue on 4th line with the function. I did research to find out, and it has to do with variables and closures. What are some ways I can fix it without using a let declaration. Will this code work to solve the problem?
I’m trying to create algorithms on my own and so far I’ve been good (except I needed to refer to hints for factorialize a number and get help from the forum for check for palindromes
).
I’m sure I can come up with another algorithm to solve this problem, but I want this one to work where I use for loop and Math.max. Just need help with the format/reworking the code to make it work.
Please if someone can help me fix this code so it works. Thank you in advance!
Your code so far
function largestOfFour(arr) {
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i]; i++) {
var maxNumber = arr[i][j].reduce(function (a,b) {
return Math.max(a,b);
});
return maxNumber;
}
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: