What is Nostr?
Fabio Manganiello /
npub13uu…pvgs
2024-03-23 23:00:09
in reply to nevent1q…7acw

Fabio Manganiello on Nostr: npub1lhngm…ss0mj for sake of completeness: #JavaScript Array.sort function by ...

npub1lhngm68szjfcqr6yptylfnupq3dyajl7h56j05zdwhllf7e0ezdsgss0mj (npub1lhn…s0mj) for sake of completeness: #JavaScript Array.sort function by default calls toString on all the items before sorting, thus the sort comparator is the string comparator.

If your array really contains only numbers (who would have think of such a corner case, right?), then you’ll have to explicitly pass a sort comparator:

❯ [1, 11, 4, 3, 2].sort((a, b) => a - b)
Array(5) [ 1, 2, 3, 4, 11 ]
Author Public Key
npub13uunvh7djw9ep54nswkuxlneyee7ehcpc7e53t68krykrdeg6j4qrdpvgs