Skip to content

Instantly share code, notes, and snippets.

@sspboyd
Created March 19, 2022 20:53
Show Gist options
  • Save sspboyd/e839bb32ca6d2493fa8257e79463e117 to your computer and use it in GitHub Desktop.
Save sspboyd/e839bb32ca6d2493fa8257e79463e117 to your computer and use it in GitHub Desktop.
Calculate fibonacci sequence based on two given starting numbers and up to a specified number of entries.
let fib_num = function (n0, n1, fib_idx) {
let next_num;
for (let i = 0; i <= fib_idx; i++) {
next_num = n0 + n1;
n0 = n1;
n1 = next_num;
}
console.log(`fibonacci number is: ${next_num}.`);
return next_num;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment