forked from wijaksanapanji/learn-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chinkeki.html
38 lines (34 loc) · 855 Bytes
/
chinkeki.html
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
<!DOCTYPE html>
<html>
<body>
<script>
//1st task
function repeat(func, param, times) {
for (let i = 1; i <= times; i++) {
func(param);
}
}
const displayLog = function(message) {
console.log(message);
};
repeat(displayLog, 'run number', 5);
//2nd Task
function repeatDuration(repeat, times, func, param) {
console.time('executiontime');
repeat(func, param, times);
console.timeEnd('executiontime');
}
repeatDuration(repeat, 5, displayLog, 'run number');
//task 3
function factorial(x) {
if (x === 0) {
return 1;
}
return x * factorial(x - 1);
}
console.log(factorial(5));
//task 4
repeatDuration(repeat, 1000, factorial, 20);
</script>
</body>
</html>