UNPKG

881 BJavaScriptView Raw
1function keys(x) {
2 return x[0];
3}
4function values(x) {
5 return x[1];
6}
7function* entries(x) {
8 var vi = values(x)[Symbol.iterator]();
9 for (var k of keys(x))
10 yield [k, vi.next().value];
11}
12function id(v) {
13 return v;
14}
15function cmp(a, b) {
16 return a < b ? -1 : (a > b ? 1 : 0);
17}
18function range(x, fc = null, fm = null) {
19 var fc = fc || cmp, fm = fm || id;
20 var mk, mu, mv;
21 var nk, nu, nv;
22 var i = 0;
23 for (var [k, u] of x) {
24 var v = fm(u, k, x);
25 if (i === 0 || fc(v, mv) < 0) {
26 mk = k;
27 mu = u;
28 mv = v;
29 }
30 if (i === 0 || fc(v, nv) > 0) {
31 nk = k;
32 nu = u;
33 nv = v;
34 }
35 i++;
36 }
37 return [[mk, mu], [nk, nu]];
38}
39function range$1(x, fc = null, fm = null) {
40 return range(entries(x), fc, fm);
41}
42export default range$1;