abbas
abbas

Reputation: 432

Javascript sort array function performance

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

Answers (1)

Daff
Daff

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

Related Questions