-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
41 lines (35 loc) · 834 Bytes
/
test.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
// 实现返回一个斐波那契函数
// let arr = [];
// (function feibo (num) {
// if (num === 1 || num === 2) {
// if (arr.length < 2) {
// arr.push(1);
// }
// return 1;
// }
// var result = arguments.callee(num - 1) + arguments.callee(num - 2);
// if (result > arr[arr.length - 1]) {
// arr.push(result);
// }
// return result;
// })(10);
// console.log(arr);
// [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
let arr = [];
function methodTwo (num) {
// return ((num) => {
if ((num === 1 || num === 2)) {
if (arr.length < 2) {
arr.push(1);
}
return 1;
}
var result = arguments.callee(num - 1) + arguments.callee(num - 2);
if (result > arr[arr.length - 1]) {
arr.push(result);
}
return result;
// })(num);
}
methodTwo(3);
console.log(arr);