forked from zero-to-mastery/JS_Fun_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchirag_solutions.js
114 lines (78 loc) · 2.19 KB
/
chirag_solutions.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const identity = x => x;
const addb = (a,b) => a + b;
const subb = (a,b) => a - b;
const mulb = (a,b) => a * b;
const minb = (a,b) => {
if(a < b){
return a
}
return b;
};
const maxb = (a,b) => {
if(a > b){
return a
}
return b;
};
const add = (...nums) => {
let total = 0;
for(let i in nums){
total = total + num[i]
}
return total;
};
const sub = (...nums) => {
let total = 0;
for(let i in nums){
total = total - num[i]
}
return total;
};
const mul = (...nums) => {
let total = 0;
for(let i in nums){
total = total * nums[i]
}
return total;
};
const min = (...nums) => {
let minNum = nums[0]
for(let i in nums){
if(nums[i] < minNum){
minNum = nums[i];
}
}
return minNum;
};
const max = (...nums) => {
let maxNum = nums[0]
for(let i in nums){
if(nums[i] > maxNum){
maxNum = nums[i];
}
}
return maxNum;
};
const addRecurse = (...nums) => {
if(nums.length === 1){
return nums[0];
}
let [first, ...rest] = nums;
return first + addRecurse(...rest);
};
const mulRecurse = (...nums) => {
if(nums.length === 1){
return nums[0];
}
let [first, ...rest] = nums;
return first * mulRecurse(...rest);
};
const not = ( func ) => {
return !func();
};
const acc = (func, initial) => {
return function(...args){
return func(initial, ...args);
}
};
module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, };