- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
'use strict';
function map(fn, array) {
let arr = [];
for(let i of array)
arr.push(fn(i));
return arr;
}
function take(fn, count) {
var arr = [];
for(let i = 0; i < count; i++)
arr.push(fn());
return arr;
}
function sequence(start, step)
{
step = step || 1;
start = start || 0;
start-=step;
return function() {
return start+=step;
}
}
function fmap(a, gen) {
return (...args) => {
if(args.length > 0)
return a(gen(...args));
else
return a(gen());
};
}
function partial(fn, ...args) {
return (...twoArgs) => {
let newM = args.slice();
for(let k of twoArgs)
newM.push(k);
return fn(...newM);
};
}
function partialAny(fn, ...args) {
return (...twoArgs) => {
let newM = args.slice();
let k = 0;
for(let i = 0; i < newM.length; i++)
if(newM[i] === undefined)
newM[i] = twoArgs[k++];
while(twoArgs[k] !== undefined) {
newM.push(twoArgs[k]);
k++;
}
return fn(...newM);
};
}
function bind(fn, context) {
return (...args) => {
return fn.apply(context, args);
};
}
function pluck(objects, fieldName) {
let a = [];
for(let i = 0; i < objects.length; i++)
if(objects[i][fieldName] !== undefined)
a.push(objects[i][fieldName]);
return a;
}
function filter(arr, fn) {
let a = [];
arr.forEach((item, i, arr) => {
if(fn(item))
a.push(item);
});
return a;
}
function count(arr) {
return Object.keys(arr).length;
}
var a = { a: 1, b: 2 };
console.log(count(a)); // 2
var b = function () {};
console.log(count(b)); // 0
var c = [1, 2, 3];
console.log(count(c)); // 3
var d = [];
d[100] = 1;
console.log(count(d)); // 1