-
Notifications
You must be signed in to change notification settings - Fork 1
/
testing.js
58 lines (47 loc) · 1016 Bytes
/
testing.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
const arr = [1, 2, 3, 4];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const test = `asd`;
asdasd
// function array(arr) {
// for (let i = 0; i < arr.length; i++) {
// sleep(1000);
// console.log(arr[i]);
// }
// }
// Immadiate invoke function expression
// (async () => {
// await array(arr);
// console.log("done");
// })();
function power(i, y) {
if (y < 1 && y > 0) {
return 1;
}
if (y < 0) {
return 1 / power(i, -y);
}
if (y !== 0) {
return i * power(i, y - 1);
}
return 1;
}
console.log(power(3, 3)); // 9
console.log(power(3, -1)); // 8
console.log(power(3, -2)); // 8
console.log(power(3, 0)); // 8
console.log(power(3, -1)); // 8
// console.log("DONE");
// async function customizeAwait(arr, cb) {
// await cb({
// index: arr[1]
// });
// }
// (async () => {
// await customizeAwait(arr, async ({ index }) => {
// await sleep(1000);
// console.log(index);
// });
// console.log("DONE");
// })();