-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (30 loc) · 853 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict'
const Hifo = require('./hifo')
const lowest = function (primary, secondary) {
if (arguments.length === 2)
return (a, b) => {
const d = a[primary] - b[primary]
if (d === 0) return a[secondary] - b[secondary]
else return d
}
if (arguments.length === 1)
return (a, b) => a[primary] - b[primary]
return (a, b) => a - b
}
const highest = function (primary, secondary) {
if (arguments.length === 2)
return (a, b) => {
var d = b[primary] - a[primary]
if (d === 0) return b[secondary] - a[secondary]
else return d
}
if (arguments.length === 1)
return (a, b) => b[primary] - a[primary]
return (a, b) => b - a
}
const factory = (sort, options) => {
const instance = Object.create(Hifo)
instance.init(sort, options)
return instance
}
module.exports = Object.assign(factory, {lowest, highest, Hifo})