I was working through the algorithm Return Largest Numbers in Arrays and I got the solution, but I was wondering if the way I attacked the problem is correct. Is part of solving these challenges figuring a way to get the solution from researching online? Obviously not copying and pasting, but to look up methods and functions on MDN appropriate?
For instance, this was my code to solve the problem:
function largestOfFour(arr) {
// You can do this!
for(var i=0; i<arr.length; i++) {
arr[i]= Math.max.apply(null, arr[i]);
}
return arr;
}
I assumed there was something related to Math.max() , so I googled it and read on how to use it in MDN. Is what I did a valid way to solve this problem? Or does FCC want us to reinvent the wheel and figure out how to solve it by what I would assume go through each array and compare the values within the arrays?
You’ve absolutely got the right idea. Looking up stuff in the MDN is excellent.
Don’t be too concerned if you need to look it up in more low-brow places either, like WS3Schools or Youtube
The goal of the bonfires is to teach you how to solve problems by breaking them down into small, reasonable processes and learning how to do those in JS. Don’t be too concerned about being as short as possible yet, or using ES6 features as Laney suggests - just focus on taking a methodical approach to problem solving and figuring out what questions to ask when you get stuck!