Skip to content

Instantly share code, notes, and snippets.

@brunocarvalhodearaujo
Last active February 18, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brunocarvalhodearaujo/bb1f5d5a15cba1596e91 to your computer and use it in GitHub Desktop.
Save brunocarvalhodearaujo/bb1f5d5a15cba1596e91 to your computer and use it in GitHub Desktop.
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