Im sorting an array of objects alphabetically but not sure which way is more efficient. Im currently using the .sort() method and its working fine but would using the localeCompare() be a better alternative?
Asked
Active
Viewed 5,414 times
1
-
1https://stackoverflow.com/questions/14677060/400x-sorting-speedup-by-switching-a-localecompareb-to-ab-1ab10 may give you some ideas and examples – skyboyer Apr 15 '19 at 19:01
-
do you mean if may `localCompare()` be faster than using `a> b? 1: -1`? – skyboyer Apr 15 '19 at 19:05
-
do you care about valid ordering for 'A', 'a' and 'ä'? – skyboyer Apr 15 '19 at 19:06
-
yeah so would be better to do `a>b ?1:-1` or just use `localeCompare()` – CatGirl19 Apr 15 '19 at 20:06
1 Answers
2
The localeCompare
function is absurdly slow on many browser. Avoid it if possible. The other locale functions are really bad too, particularly the number to string ones.

le3th4x0rbot
- 2,493
- 23
- 32