The problem i'm getting is that globalArray shoud not change... I've tried multiple logic but the error won't letting me to complete the test

Tell us what’s happening:
Describe your issue in detail here.

  **The globalArray variable should not change.**

const globalArray = [2, 3, 5, 6, 9];

function nonMutatingSort(arr) {
// Only change code below this line
let output = [];


 output =  arr.slice().sort(function(a, b) {return a-b})
  arr = output;

 return arr;
// Only change code above this line
}

console.log(nonMutatingSort(globalArray));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Return a Sorted Array Without Changing the Original Array

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


You probably shouldn’t have manually sorted the globalArray.

2 Likes