From 8269037faad5288ce36146f99e03c372724292c6 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 13 Nov 2024 07:21:42 +0100 Subject: [PATCH] chore: perf --- src/utils/dataByOrder.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/dataByOrder.js b/src/utils/dataByOrder.js index 72b55ac11..1bdedb8a1 100644 --- a/src/utils/dataByOrder.js +++ b/src/utils/dataByOrder.js @@ -1,4 +1,5 @@ function orderData(data, order) { + if (typeof order === 'function') return data.sort(data); if (typeof order === 'string') order = [order]; if (Array.isArray(order)) { let orderComp = []; @@ -12,13 +13,13 @@ function orderData(data, order) { } return data.sort((a, b) => sortFunc(a, b, orderComp)); - } else if (typeof order === 'function') return data.sort(data); + } return data; } function sortFunc(a, b, order) { - for (let i of order) { - let compRes = compareFunc(a[i.field], b[i.field]) * i.way; + for (let { field, way } of order) { + let compRes = compareFunc(a[field], b[field]) * way; if (compRes !== 0) return compRes; }