how does sort() work

i wanna know how sort () works
8 Replies
cat
cat•9mo ago
so imagine i created an array
cat
cat•9mo ago
mozilla😭 actually my concern is with whats being printed in the console option i will retake the screenshot
cat
cat•9mo ago
No description
cat
cat•9mo 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•9mo 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
cat•9mo ago
oh now i got it thanks😀
Jochem
Jochem•9mo ago
np 🙂
Want results from more Discord servers?
Add your server