-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
79 lines (64 loc) · 1.74 KB
/
test.js
File metadata and controls
79 lines (64 loc) · 1.74 KB
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
const proba = [
['gazon', 10],
['shrek', 70],
['boris', 20]
];
const probaWithBound = [];
let totalProb = proba.reduce((acc, elm) => {
probaWithBound.push(...elm, acc);
return acc + elm[1];
}, 0);
const getOne = (probaWithBound, totalProb) => {
const choosen = Math.random() * totalProb;
return probaWithBound.reduceRigth((acc, elm) => (choosen <= elm[2] ? elm[0] : acc));
};
///// Test Curryfication function
const currier = fnToCurry => {
const curried = ({ fun, args, prevArgs }) => {
if (fun.length <= args.length + prevArgs.length) {
return fun(...prevArgs, ...args);
} else {
return (...nextArgs) => curried({ args: nextArgs, prevArgs: [...prevArgs, ...args], fun });
}
};
return (...args) =>
curried({
fun: fnToCurry,
args: args,
prevArgs: []
});
};
const CurryIt = fun => {
const curried = (...args1) => {
const fn = (...args2) => fun(...args1, ...args2);
fn.valueOf = () => fun(...args1);
return fn;
};
};
function CurryIt(func) {
let fn = func;
let that;
return function(...args) {
if (!that) that = this;
if (args.length === 0) {
const result = fn();
fn = func;
return result;
}
fn = fn.bind(that, ...args);
};
}
const memo = fun => {
const args = [];
const f = fun;
return (...nextArgs) => {
args = [...args, ...nextArgs];
if (nextArgs.length === 0) return fun(...args);
};
};
const add = (...args) => args.reduce((acc, item) => acc + item, 0);
const myMap = new Map();
let stringRandom = "";
myMap.forEach((value,key) => {
stringRandom += `${value} \n`;
})