Return a Sorted Array Without Changing the Original Array -?

Return a Sorted Array Without Changing the Original Array -?
0

#1

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);

#2

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


#3

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


#4

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


#5

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.


#6

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!