-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (33 loc) · 873 Bytes
/
Copy pathtest.js
File metadata and controls
35 lines (33 loc) · 873 Bytes
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
var ClimbFrog = (n) => {
if (n <= 0) {
return 0;
} else if (n == 1) {
return 1;
} else if (n == 2) {
return 2;
} else {
var result = ClimbFrog(n - 1) + ClimbFrog(n - 2);
return result;
}
}
function ClimbFrog_1(floorAmount) {
if (floorAmount <= 0) {
return 0;
} else if (floorAmount == 1) {
return 1;
} else if (floorAmount == 2) {
return 2;
} else {
var result = 0;
var resultFormerOne = 1;
var resultFormerTwo = 2;
for (let index = 2; index < floorAmount; index++) {
result = resultFormerOne + resultFormerTwo;
resultFormerOne = resultFormerTwo;
resultFormerTwo = result;
}
return result;
}
}
console.log(ClimbFrog(10))
console.log(ClimbFrog_1(10))