/*1..toSorted */
//traditional sort
//it mutates
var arr = [1,54,2,14,6]
var newArr= arr.sort((a,b)=>a-b);
console.log(arr); //[ 1, 2, 6, 14, 54 ]
console.log(newArr); //[ 1, 2, 6, 14, 54 ]
/*original array also gets sorted..
but what if we dont want to disturb
the original array then use .toSorted()*/
var arr1 = [1,54,2,14,6]
var newArr1= arr.toSorted((a,b)=>a-b);
console.log(arr1); //[ 1, 54, 2, 14, 6 ]
console.log(newArr1); //[ 1, 2, 6, 14, 54 ]