Could someone please explain to me what is wrong with my code. I tested it in VS Code and it returned all test responses. correctly. But i cant seem to pass the last two tests in the freeCodeCamp console.
Thanks in advance.
const globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Only change code below this line
arr = globalArray.slice()
return arr.sort((a, b) => a - b);
// Only change code above this line
}
nonMutatingSort(globalArray);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Challenge: Functional Programming - Return a Sorted Array Without Changing the Original Array
Link to the challenge: