|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
799 bytes
|
| Line | |
|---|
| 1 | import { compareValues } from '../_internal/compareValues.mjs';
|
|---|
| 2 |
|
|---|
| 3 | function orderBy(arr, criteria, orders) {
|
|---|
| 4 | return arr.slice().sort((a, b) => {
|
|---|
| 5 | const ordersLength = orders.length;
|
|---|
| 6 | for (let i = 0; i < criteria.length; i++) {
|
|---|
| 7 | const order = ordersLength > i ? orders[i] : orders[ordersLength - 1];
|
|---|
| 8 | const criterion = criteria[i];
|
|---|
| 9 | const criterionIsFunction = typeof criterion === 'function';
|
|---|
| 10 | const valueA = criterionIsFunction ? criterion(a) : a[criterion];
|
|---|
| 11 | const valueB = criterionIsFunction ? criterion(b) : b[criterion];
|
|---|
| 12 | const result = compareValues(valueA, valueB, order);
|
|---|
| 13 | if (result !== 0) {
|
|---|
| 14 | return result;
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 | return 0;
|
|---|
| 18 | });
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | export { orderBy };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.