1 | var indexedMap = require('../utilities/indexed_map')
|
2 | var map = require('../utilities/map')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function sortValues (values, isArray) {
|
11 | var sorted = values.sort(function (left, right) {
|
12 | var a = left.criteria
|
13 | var b = right.criteria
|
14 | if (a !== b) {
|
15 | if (a > b || a === void 0) return 1
|
16 | if (a < b || b === void 0) return -1
|
17 | }
|
18 | return a.index - b.index
|
19 | })
|
20 |
|
21 | if (isArray === false) {
|
22 | return indexedMap(sorted, function (res) { return [ res.key, res.value ] })
|
23 | } else {
|
24 | return map(sorted, function (res) { return res.value })
|
25 | }
|
26 | }
|