DEV Community

Discussion on: Simplest way to compare two numbers array in JS

Collapse
 
jdforsythe profile image
Jeremy Forsythe

Your function mutates the arrays. After calling compareArr(), array2 will have been sorted. You should copy the arrays before sorting so you don't mutate the parameters