Last active
February 18, 2020 18:58
-
-
Save brunocarvalhodearaujo/bb1f5d5a15cba1596e91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Fibonacci { | |
/** | |
* @param {number} value | |
* @returns {number} | |
*/ | |
sequence (value) { | |
return (value < 2) ? value : this.sequence(value - 1) + this.sequence(value - 2) | |
} | |
/** | |
* @param {number} times | |
* @returns {Array<number>} | |
*/ | |
run (times) { | |
return [ ...Array(times).keys() ].map(key => this.sequence(key)) | |
} | |
} | |
console.log(new Fibonacci().run(40)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment