Hi everyone,
In this exercise
https://www.freecodecamp.com/challenges/return-largest-numbers-in-arrays
I tried using the spread method
I’m using the code: manNum = Math.max(…arr[i]); According to the page … is used to spread the elements of the array, so the elements are send as the parameters. But I’m not sure I am using the syntax correctly. Anywasy I’m getting a message in the editor that the spread/rest operator only available in Es6.
Is my syntax correct? (…arr[i]) ?
Why doesn’t it work?
The spread operator does work. Your issue is not with the spread operator.
Your other logic isn’t correct.
return
statements cause functions to halt and return. If you’re trying to do a return inside of a loop (without having it inside of another conditional block) it will cause the function to halt and return the information that you specify.
Ergo, your loop isn’t really a loop.
@carpben I think there is something wrong with the condition in the for
loop.
Can you paste your code here?
what is i < i.length()
?. your loop condition is not correct. that es6 warning is just there to remind you that the funcion/method you are using might not be available in some browsers
Yes, there were a few problems with the code. I actually just wanted to confirm that the syntax ‘…’ was correct because I have never seen or used it before. Thanks everyone for your help!!!