You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
);// or return {...h, name: h.name.toUpperCase()};
190
190
191
191
console.log(heroes);
192
+
193
+
// What is the problem with sort() function? Why javascript introduced toSorted() function
194
+
195
+
/**
196
+
* Ans: sort() function mutates the original array
197
+
* toSorted() method takes an array and returns a new array with the elements sorted in ascending order. It does not mutate the original array. All undefined elements are sorted to the end of the array.
198
+
* */
199
+
200
+
constarr=[1,8,6,9,7,100,400,200];
201
+
202
+
constoldSortedArr=arr.sort((a,b)=>a-b);
203
+
204
+
console.log(arr);// [1, 6, 7, 8, 9, 100, 200, 400] (mutated the original array)
0 commit comments