Reputation: 432
Does anyone know how the built-in JS function array.sort()
functions internally? I mean does it change strings to numbers....etc
var keys = new Array();
keys.sort();
Upvotes: 2
Views: 3931
Reputation: 44215
From the MDN docs for sort():
If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic ("dictionary" or "telephone book," not numerical) order. For example, "80" comes before "9" in lexicographic order, but in a numeric sort 9 comes before 80.
Refer to the answers of this question as to what algorithm is being used.
Upvotes: 7