how does sort() work

i wanna know how sort () works
8 Replies
cat
catOP•10mo ago
so imagine i created an array
cat
catOP•10mo ago
mozilla😭 actually my concern is with whats being printed in the console option i will retake the screenshot
cat
catOP•10mo ago
No description
cat
catOP•10mo ago
here is the code and the console page i wanna know why when i declared the value of array[12] and array [29] and used the sort() function then in the console, it shifted the value to array[0] and array [1] rather than array[12] and array[29]
Jochem
Jochem•10mo ago
because it's been sorted From the MDN article:
If compareFn is not supplied, all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order. For example, "banana" comes before "cherry". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in the Unicode order. All undefined elements are sorted to the end of the array.
cat
catOP•10mo ago
oh now i got it thanks😀
Jochem
Jochem•10mo ago
np 🙂
Want results from more Discord servers?
Add your server