Algorithms and Data Structures · Junior · Question 36 of 75
What is important to remember about arr.sort()?
- ✓Correct answer: It sorts the array in place and returns the same array
- 2It returns a new sorted array and leaves the original intact
- 3It only works on arrays of strings
Explanation
sort mutates the original array, which can surprise code that still uses it, for example React state. toSorted() (ES2023) returns a sorted copy instead.