-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonnaci_sequence.js
More file actions
60 lines (50 loc) · 1.2 KB
/
Copy pathfibonnaci_sequence.js
File metadata and controls
60 lines (50 loc) · 1.2 KB
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
59
60
// function fibonacciGenerator(n) {
// var output = [];
// if (n === 1) {
// output = [0];
// return output;
// } else if (n === 2) {
// output = [0, 1];
// return output;
// } else {
// output = [0, 1];
// count = 1;
// while(count < (n-1))
// {
// output.push(output[count] + output[count-1]);
// count++;
// }
// return output;
// }
// }
// fibonacciGenerator(10);
// function fibonacciGenerator(n) {
// var output = [];
// switch (n) {
// case 1:
// output = [0];
// break;
// case 2:
// output = [0, 1];
// break;
// default:
// output = [0, 1];
// while (output.length !== n) {
// output.push(output[output.length - 1] + output[output.length - 2]);
// }
// break;
// }
// return output;
// }
function fibonacciGenerator(n) {
var output = [];
for (var i = 0; i < n; i++) {
var len = output.length;
if (i < 2)
output.push(i);
else
output.push(output[len - 1] + output[len - 2]);
}
return output;
}
fibonacciGenerator(10);