I think your example code is a bit off
const array = [6,-2,2,-7]; array.sort((a,b)=>{ a-b; });
The arrow function you've supplied here always returns undefined.
I think you intended to write this instead:
const array = [6,-2,2,-7]; array.sort((a, b) => a - b);
The moral of this story is to always test your examples. :)
Same with that one ;) (missing the return):
return
const array = [6,-2,2,-7]; array.sort(function(a,b){ a-b; });
to work it should be:
const array = [6,-2,2,-7]; array.sort(function(a,b){ return a-b; });
Haha, Oh my God. I completely missed that. Thanks for the heads up
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think your example code is a bit off
The arrow function you've supplied here always returns undefined.
I think you intended to write this instead:
The moral of this story is to always test your examples. :)
Same with that one ;) (missing the
return
):to work it should be:
Haha, Oh my God. I completely missed that. Thanks for the heads up