Why is this solution not working?

It’s telling me that nonMutatingSort([1, 30, 4, 21, 100000]) should return [1, 4, 21, 30, 100000]. When I paste that input array into my code, delete “return” and console.log(newArr), it gives me that output array. What am I doing wrong?

  **Your code so far**

var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Only change code below this line
let newArr = globalArray.slice()
return newArr.sort((a,b) => a-b)
// Only change code above this line
}
nonMutatingSort(globalArray);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Firefox/90.0

Challenge: Return a Sorted Array Without Changing the Original Array

Link to the challenge:

You don’t want to work with the global array declared outside of the function, you want to work with the array passed into the function.

1 Like

Oh sheesh duh! Thanks

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.