Skip to content

Instantly share code, notes, and snippets.

@jecsham
Forked from brunocarvalhodearaujo/fibonacci.ts
Last active February 18, 2020 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jecsham/b0ef802e0c051def6e62a66ced17abd6 to your computer and use it in GitHub Desktop.
Save jecsham/b0ef802e0c051def6e62a66ced17abd6 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(50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment