-
Notifications
You must be signed in to change notification settings - Fork 1
/
4.3.js
executable file
·46 lines (39 loc) · 963 Bytes
/
4.3.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
44
45
46
var filterById = autoCurry(function (id, item) {
return id === item.id;
});
var find = autoCurry(function (pred, coll) {
for (var i = 0, l = coll.length; i < l; i++) {
if (pred(coll[i])) {
return coll[i];
}
}
});
var eq = autoCurry(function (v1, v2) {
return v1 === v2;
});
function getPage(id, pages) {
return find(compose(eq(id), prop('id')), pages);
}
function curry(fn, args, length) {
length = length || fn.length;
return function (arg) {
var allArgs = (args || []).concat([].slice.call(arguments, 0, 1));
if (allArgs.length === length) {
return fn.apply(this, allArgs);
} else {
return curry(fn, allArgs);
}
};
}
function autoCurry(fn, length) {
return function () {
if (arguments.length >= (length || fn.length)) {
return fn.apply(this, arguments);
} else {
return curry(fn, [], length);
}
};
}
var prop = autoCurry(function (name, obj) {
return obj[name];
});