Merge branch 'main' into main

This commit is contained in:
Alex Younger
2023-11-15 20:39:53 -05:00
committed by GitHub
6 changed files with 4730 additions and 4993 deletions
+10 -2
View File
@@ -13,7 +13,7 @@ const fibonacci = function(countArg) {
let firstPrev = 1;
let secondPrev = 0;
for (let i = 2; i <= count; i++) {
let current = firstPrev + secondPrev;
secondPrev = firstPrev;
@@ -21,6 +21,14 @@ const fibonacci = function(countArg) {
}
return firstPrev;
};
module.exports = fibonacci;
// Another way to do it is by using an iterative approach with an array containing two values, 0 and 1.
// const fib = [0, 1];
// for (let i = 2; i <= count; i++) {
// fib[i] = fib[i - 1] + fib[i - 2];
// }
// return fib[count];
module.exports = fibonacci;