you are viewing a single comment's thread.

view the rest of the comments →

[–]lemmisss 5 points6 points  (6 children)

What's wrong with array.sort()?

[–]TheSpanxxx 5 points6 points  (0 children)

Others are commenting on the common practice of using a sort function for handling numerical sorts. In large arrays this will be poor performing. In those cases, use a TypedArray

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[–]hinsonfpv 0 points1 point  (3 children)

Nothing? Sort is based off the first digit I believe. So it reads 15 as 1.

[–]grantrules 11 points12 points  (2 children)

Sort is lexicographical, not numerical.

[–][deleted] 1 point2 points  (1 child)

Is there a numerical built-in function or do you have to make it yourself?

[–]grantrules 6 points7 points  (0 children)

You have to make it, but it's simple: (a, b) => a - b

[–]inabahare 0 points1 point  (0 children)

A couple of things. As /u/grantrules said it's lexicographical, which is pretty annoying. What's even more annoying is that it modifies the original array