You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
361 B
25 lines
361 B
const Fibonacci_Cycle = (n: number): number => { |
|
if (n <= 0) return 0; |
|
if (n === 1) return n; |
|
|
|
let n1 = 0; |
|
let n2 = 0; |
|
let n3 = 0; |
|
|
|
for (let index = 0; index <= n; index++) { |
|
if (index === 1) { |
|
n1 = 0; |
|
n2 = 1; |
|
|
|
continue; |
|
} |
|
|
|
n3 = n1 + n2; |
|
n1 = n2; |
|
n2 = n3; |
|
} |
|
|
|
return n3; |
|
}; |
|
|
|
console.log(Fibonacci_Cycle(6));
|
|
|