Quiz time! What's wrong with our customMax
function? How do we fix it?
Hint: check out the second image, where we show "customMax" in use
For further actions, you may consider blocking this person and/or reporting abuse
Prince -
reverse Ch -
Saleh Mubashar -
Muhammad Awais -
Top comments (1)
All non-primitives are passed by reference in es, so we're effectively passing the same array to the sort function. That's why the array is sorted afterwards. The solution would be to clone the array to a new variable before sorting it (i.e. by using the spread operator
const larr = [...arr]
)