ES6 - Use the Spread Operator to Evaluate Arrays In-Place

Tell us what’s happening:
Describe your issue in detail here.

I don’t understand this explanation one the null requirement. Why do you not need max and apply methods anymore once you use spread?

And why you need them to avoid NaN if you don’t spread?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: ES6 - Use the Spread Operator to Evaluate Arrays In-Place

Link to the challenge:

Math.max() expects numbers
arr is not a number, but an array, so writing Math.max(arr) you are feeding something that is not a number to a method that expects a number, so it returns NaN

Math.max.apply(null, arr) is a way to use a method that accepts multiple arguments with an array.
The spread operator spread the array to multiple arguments when you do Math.max(...arr) so that’s not needed anymore.
It can be confusing if you don’t already know how it was done before.

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