Functional Programming - Return a Sorted Array Without Changing the Original Array

Tell us what’s happening:

Describe your issue in detail here.
I keep testing various solution and none of them are coming through. What is wrong?

Your code so far

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

function nonMutatingSort(arr) {
  // Add your code below this line
  let newArr = [].concat(arr);
  return newArr.sort((a, b) => a - b);
  // Add your code above this line
}

console.log(nonMutatingSort(globalArray));
console.log(globalArray)

Your browser information:

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

Challenge Information:

Functional Programming - Return a Sorted Array Without Changing the Original Array

Did you change the first line to const globalArray = [2, 3, 5, 6, 9];?
Try resetting it to what it was originally

1 Like

Yep, was just going to say the same thing. When the comments only tell you to change code in a certain area then be sure not to change any existing code outside of that area.

I did that, but still don’t pass the “The globalArray variable should not change.” test

Did you actually reset the challenge to get the original code back?

The code you added to the function body worked for me. I just needed to put the original array back to exactly what it was.

If you did reset the challenge, then perhaps you might need to force a refresh on your browser cache and then reload the page. Maybe even exit out of your browser and then open it again.

1 Like

Thanks, that worked!

2 Likes

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