-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (50 loc) · 1.04 KB
/
index.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
// # Problem 2619
Array.prototype.last = function () {
return this.length > 0 ? this[this.length - 1] : -1;
};
const arr = [];
console.log(arr.last());
// Problem 2620. Leet Code
var createCounter = function (n) {
const counter = n - 1;
return function () {
counter++;
return counter;
};
};
// Problem 2621. Leet Code
async function sleep(millis) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, millis);
});
}
// Problem 2626
var reduce = function (nums, fn, init) {
for (i = 0; i < nums.length; i++) {
init = fn(init, nums[i]);
}
return init;
};
console.log(
reduce(
[1, 2, 3, 4],
function sum(accum, curr) {
return accum + curr * curr;
},
100
)
);
// Problem 2629
var compose = function (functions) {
return function (x) {
let modX = x;
for (i = functions.length - 1; i >= 0; i--) {
modX = functions[i](modX);
}
return modX;
};
};
const fn = compose([(x) => 10 * x, (x) => 10 * x, (x) => 10 * x]);
console.log(fn(1)); // 1000