Return a Sorted Array Without Changing the Original Array -?

I feel like I’m missing something here. The console logs the correct answer, but it still fails. Maybe I’m logging wrong?

Can someone provide a clue as to what’s wrong?

var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
  // Add your code below this line
  
  var myArray = arr.concat();

  return console.log(myArray.sort(function(a, b) {
    return a - b;
  }));
  
  // Add your code above this line
}
nonMutatingSort(globalArray);

You should return the sorted array without passing it to console.log()

It still fails without the console.log; That was just to see what was happening and I had forgotten to remove it :slight_smile:

It passes here though :confused:
Try resetting the exercise first

I’m glad to know that it’s at least passing lol

I’ve reset the exercise, to no avail. I’ve tested it in Chrome as well.

I’m still debugging it and will update if I find anything.

Strange. I removed the first console.log (as I did prior) but then logged the function call to the console and it passed. I then removed that console.log() and it passed. Not sure what I missed but I’m just glad it works now.

Thanks!

I am a total noob and just started learning to code on freecodecamp, 2 weeks back. It’s an awesome resource.

For this, I am proud that I got the following solution, without any “cheating” all by myself :slight_smile:

let newArray = arr.concat();
return newArray.sort();