From 04892f1fc5916d2764acc8249a15f95be7f9f82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Fri, 29 Sep 2023 00:09:11 -0400 Subject: [PATCH] Detect asc as the second parameter --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 998c465..61a7698 100644 --- a/index.js +++ b/index.js @@ -9,9 +9,15 @@ const sortby = (properties) => (a, b) => { const property = properties[i] let order = -1 - if (i + 1 < properties.length && properties[i + 1] === 'desc') { - order = 1 - i++ + if (i + 1 < properties.length) { + const next = properties[i + 1] + + if (next === 'desc') { + order = 1 + i++ + } else if (next === 'asc') { + i++ + } } const compare = collator.compare(a[property], b[property])