Update fibonacci-solution.js

This commit is contained in:
Nathan 2023-07-05 09:15:36 -05:00 committed by GitHub
parent 76551b0e8a
commit fcb1c4971a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -2,16 +2,18 @@ const fibonacci = function(count) {
if (count < 0) return "OOPS"; if (count < 0) return "OOPS";
if (count === 0) return 0; if (count === 0) return 0;
let first_prev = 1; let firstPrev = 1;
let second_prev = 0; let secondPrev = 0;
// For clarification: curr stands for current. This is standard syntax
for (let i = 2; i <= count; i++) { for (let i = 2; i <= count; i++) {
let curr = first_prev + second_prev; let curr = firstPrev + secondPrev;
second_prev = first_prev; secondPrev = firstPrev;
first_prev = curr; firstPrev = curr;
} }
return first_prev; return firstPrev;
}; };
module.exports = fibonacci; module.exports = fibonacci;