sanjar-notes / web_dev_fundamentals

The basics - HTML, CSS, Javascript and more
https://sanjar-notes.github.io/web_dev_fundamentals/
3 stars 0 forks source link

Natural sorting (1, 2, 10, 11) option in `localeCompare` #100

Open sanjarcode opened 10 months ago

sanjarcode commented 10 months ago

normal localeCompare sorts [1, 2, 10, 11] as [1, 10, 11, 2] (undesirable). of course, these are strings.

fix:

'10'.localeCompare('2', undefined, {numeric: true, sensitivity: 'base'})

source: https://stackoverflow.com/a/38641281/11392807 important