Skip to content

Instantly share code, notes, and snippets.

@DesignFront
Last active March 4, 2021 10:18
Show Gist options
  • Save DesignFront/6fd2a7df05bf3aad2f44b5222a0cf2f7 to your computer and use it in GitHub Desktop.
Save DesignFront/6fd2a7df05bf3aad2f44b5222a0cf2f7 to your computer and use it in GitHub Desktop.
Fibonacci
// get the fib number:
function fib(n) {
let arr = [0,1,1];
for (let i = 3; i <= n; i++) {
arr.push(arr[i-2] + arr[i-1])
}
return arr[n]
}
// get first 30 numbers:
for (let i=0; i<30; i++) {
console.warn(fib(i));
}
//////////
function fibonacci(num) {
if (num <= 1) return 1;
return fibonacci(num - 1) + fibonacci(num - 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment