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

Tell us what’s happening:
Describe your issue in detail here
return arr.slice().sort();
This method results [ 1, 100000, 21, 30, 4 ] as its sorted array
why does this method displays wrong sorted array ??sort is not proper if one of the element is too large??
Your code so far

const globalArray = ([1, 30, 4, 21, 100000]);

function nonMutatingSort(arr) {
  // Only change code below this line
  // return [].concat(arr).sort(function(a,b){
  //   return a-b
  // }
  // );
  return arr.slice().sort();
  // Only change code above this line
}

console.log(nonMutatingSort(globalArray));

Your browser information:

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

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

Link to the challenge:

Why did you change globalArray?

You are not supposed to change it. See the second test:

The globalArray variable should not change.

i know not to change global array but i tried to solve this challenge by using slice and sort method .it worked properly with deafult global array as input but i was not not able to sort this array properly .

That is because you need to use a compare function as the argument for the sort method. Look here for more information about the sort method.

The reason the one array does not sort as expected was taught in the previous challenge.