Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Last active January 22, 2018 12:01
Show Gist options
  • Save audunolsen/ba0e567bbdd8661d35aff9231f75d49c to your computer and use it in GitHub Desktop.
Save audunolsen/ba0e567bbdd8661d35aff9231f75d49c to your computer and use it in GitHub Desktop.
A Javascript function returning an array with the desired length of the Fibonacci sequence
const fibonacci = length => {
const fibSeq = [1, 1];
if(length < 2) return fibSeq.splice(length, length);
for(let i = 2; i < length; i++) fibSeq.push(fibSeq[i-2] + fibSeq[i-1]);
return fibSeq;
}
console.log(fibonacci(50));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment