sanjar-notes / frontend

The basics - HTML, CSS, Javascript, browser APIs, performance
3 stars 0 forks source link

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

Open sanjarcode opened 1 year ago

sanjarcode commented 1 year 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