Last active
April 12, 2017 19:24
-
-
Save thestephenmarshall/2ff19120a19891300a21552ea90ada8f to your computer and use it in GitHub Desktop.
ES6 Fibonacci Sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Author
thestephenmarshall
commented
Apr 12, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment