From 3b0a56ba50ea92a4a5ab1d4ee3c913324907c158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Tue, 19 Sep 2023 11:47:05 -0400 Subject: [PATCH] Sort by human number 1, ..., 9, 10 and not 1,10, 2 --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b83bb72..093123f 100644 --- a/index.js +++ b/index.js @@ -11,8 +11,11 @@ const sortby = (properties) => (a, b) => { i++ } - if (a[property] < b[property]) return order - if (a[property] > b[property]) return -order + const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }) + const compare = collator.compare(a[property], b[property]) + if (compare > 0) return order + if (compare < 0) return -order + } return 0