Question regarding solutions in the hints section - Basic Algorithm Scripting - Return Largest Numbers in Arrays

I’ve recently started checking the solutions on the hints page after solving a challenge to see how my solution compares to the ones provided. Is there any benefit to doing this for someone like me who is completely new to programming? The reason I ask is that I was super happy to have come up with the solution (I stole the Math.max method from a google search btw) but when I looked at the solutions provided on the hint page only 1 of the 4 made sense to me, while the other 3 flew right over my head.

While none of the solutions used the exact method I used, I got a little discouraged by my lack of understanding of the ones that were used. At this early stage, should I ignore the other methods and focus on what works for me, learning about the others later, or should I slow down and try to grasp the other concepts that are being used?

function largestOfFour(arr) {

let newArray = []

for (var i = 0; i < arr.length; i++) {
  let arrValue = arr[i];
  let highValue = 0;
  highValue = Math.max(...arrValue)
  newArray.push(highValue);
  
}


  return newArray;
}

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_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

I found it very useful to compare my solutions with those provided in the curriculum. I learned a great deal from understanding alternative approaches, more elegant, efficient or innovative ideas or even (occasionally) the confidence boost of realising that my solution was just better!

Yes! It is a fantastic idea to check other solutions after you have written your own.

You will see methods you haven’t learned about yet, but you will also see things you should think about and try. The more you practice, the more these other solutions will make sense to you.

Note - you should not be using var at all. It’s a legacy feature.

I’d use const everywhere possible, personally

Thank you for the feedback!

That’s very nice, thank you for the tip!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.