Return Largest Numbers in Arrays(making sure my notes provide an accurate description)

Return Largest Numbers in Arrays(making sure my notes provide an accurate description)
0.0 0


Tell us what’s happening:
I used the read-search-ask formula, except this time I didn’t have to ask anybody. While it’s a great sign of improvement, I’m hoping that my notes demonstrate a good understanding my solution. There have been many times where I came up with solutions and did not understand an ounce of what I typed.

Your code so far

function largestOfFour(arr) {
  // You can do this!
  var largestArr ={//.map was used to iterate through all subarrays
    return Math.max.apply(null,num);//Math.max returns the largest value in an array, .apply helps execute the values selected by Math.max. When .apply method is used, I pass null as an argument so that the num arg can be returned.
  return largestArr;

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:


I believe another explanation of the above line could be something like:

Math.max returns the largest value in the array arr The apply function allows arr’s elements to be treated as parameters to the Math.max function. The first parameter, you pass to the apply of any function, will be the this inside that function. Math.max does not depend on the current context of this, so, we can substitute anything for the first parameter. null is typically used to represent this fact. You could have written the same line as any of the following and achieved the same results:

return Math.max.apply("anyValueCanGoHere",num);

return Math.max.apply(undefined,num);

return Math.max.apply(1000000,num);

var obj = {prop1: "value1", prop2: "value2"};
return Math.max.apply(obj, num);

return Math.max.apply(Math, num);