-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.js
42 lines (39 loc) · 951 Bytes
/
14.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
function repeat(operation, num) {
// Modify this so it doesn't cause a stack overflow!
if (num <= 0) return;
setTimeout(function() {
trampoline(operation);
repeat(operation, --num);
}, 0);
return;
}
function trampoline(fn) {
// You probably want to implement a trampoline!
setTimeout(function() {
fn();
}, 0);
}
module.exports = function(operation, num) {
// You probably want to call your trampoline here!
return repeat(operation, num)
}
// official answer
// function repeat(operation, num) {
// return function() {
// if (num <= 0) return
// operation()
// return repeat(operation, --num)
// }
// }
//
// function trampoline(fn) {
// while(fn && typeof fn === 'function') {
// fn = fn()
// }
// }
//
// module.exports = function(operation, num) {
// trampoline(function() {
// return repeat(operation, num)
// })
// }