Merge branch 'TheOdinProject:main' into fix_Fibonacci_README

This commit is contained in:
Rushil Jalal
2023-07-30 10:42:45 +05:30
committed by GitHub
10 changed files with 84 additions and 74 deletions
+13 -6
View File
@@ -1,10 +1,17 @@
const fibonacci = function(count) {
if (count < 0) return "OOPS"
const fibPart = [0, 1];
for (let index = 1; index < count; index++) {
fibPart.push(fibPart[index] + fibPart[index -1]);
}
return fibPart[count];
if (count < 0) return "OOPS";
if (count === 0) return 0;
let firstPrev = 1;
let secondPrev = 0;
for (let i = 2; i <= count; i++) {
let current = firstPrev + secondPrev;
secondPrev = firstPrev;
firstPrev = current;
}
return firstPrev;
};
module.exports = fibonacci;