Tell us what’s happening:
Can someone help me understand why my code for this solution isn’t working just so I am aware that I don’t make these types of mistakes in the future? I see that the global array should not be hardcoded but I’m not entirely sure what that means. Thank you!
Your code so far
var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Only change code below this line
var newArr = globalArray.slice(0,5)
newArr.sort(function(a, b) {
return a - b
})
return newArr
// Only change code above this line
}
nonMutatingSort(globalArray);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.
Challenge: Return a Sorted Array Without Changing the Original Array
Link to the challenge: