I found the following code to be used to find the maximum of an array of values. I understand the concept of the array object in addition to Math.max but this is the first time that I’ve seen “apply” and I’m not sure how this particular code does what it does. If someone wouldn’t mind giving me a quick explanation, I’d appreciate it.
.apply() is especially useful for functions that can take multiple arguments (like Math.max). It’s also useful in that it can accept a context as it’s first argument which will scope the functions ‘this’ variable, and the arguments can be programmatic-ally altered without changing the implementation of the function.