source: node_modules/es-toolkit/dist/array/orderBy.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 909 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const compareValues = require('../_internal/compareValues.js');
6
7function orderBy(arr, criteria, orders) {
8 return arr.slice().sort((a, b) => {
9 const ordersLength = orders.length;
10 for (let i = 0; i < criteria.length; i++) {
11 const order = ordersLength > i ? orders[i] : orders[ordersLength - 1];
12 const criterion = criteria[i];
13 const criterionIsFunction = typeof criterion === 'function';
14 const valueA = criterionIsFunction ? criterion(a) : a[criterion];
15 const valueB = criterionIsFunction ? criterion(b) : b[criterion];
16 const result = compareValues.compareValues(valueA, valueB, order);
17 if (result !== 0) {
18 return result;
19 }
20 }
21 return 0;
22 });
23}
24
25exports.orderBy = orderBy;
Note: See TracBrowser for help on using the repository browser.