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
Anmol Baranwal -
Emil Pearce -
Mukarram Javid -
MD ARIFUL HAQUE -
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]
)