Skip to content

Commit 6dbc840

Browse files
feat: fib algo being thought out
1 parent e891f89 commit 6dbc840

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ export function addNumbers(values: number[]): number {
113113
* @return An array containing the first `n` Fibonacci values.
114114
*/
115115
export function getFirstNFibonacciNumbers(n: number): number[] {
116-
const nums = [];
116+
console.log("n = " + n);
117+
let current = 1;
117118
let prev = 0;
118-
for (let i = 1; i < n; i++) {
119-
const next = i + prev;
120-
prev = i;
119+
let temp = current;
121120

122-
console.log(next);
121+
for (let i = 1; i < n; i++) {
122+
current += prev;
123+
temp = current;
124+
prev = temp;
125+
console.log(current);
123126
}
124127
return [];
125128
}

0 commit comments

Comments
 (0)