Skip to content

Instantly share code, notes, and snippets.

@thestephenmarshall
Last active April 12, 2017 19:24
Show Gist options
  • Save thestephenmarshall/2ff19120a19891300a21552ea90ada8f to your computer and use it in GitHub Desktop.
Save thestephenmarshall/2ff19120a19891300a21552ea90ada8f to your computer and use it in GitHub Desktop.
ES6 Fibonacci Sequence
// https://es6console.com/j1fcx8bv
const fibonacci = (startNum=0, prevNum, stopAt=88) => {
let newNum;
if(typeof(prevNum) === 'undefined') {
newNum = startNum || 1;
console.log('start fibonacci...');
console.log(startNum);
fibonacci(startNum, newNum, stopAt);
return;
}
newNum = prevNum + startNum;
if(newNum > stopAt) {
console.log('...end fibonacci');
return;
}
console.log(newNum);
fibonacci(newNum, startNum, stopAt);
};
fibonacci();
@thestephenmarshall
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment