From 7e950a12f59749cdba435ab0295b8e2346d03958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Thu, 28 Sep 2023 22:53:58 -0400 Subject: [PATCH] Extract collator --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4dc4755..af4c5e8 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ const sortby = (properties) => (a, b) => { + const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }) + // if items is {prop1:value1, prop2:value2} // then sort(['prop1', 'desc', 'prop2']) // will sort by prop1 desc and prop2 @@ -11,7 +13,6 @@ const sortby = (properties) => (a, b) => { i++ } - 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