Skip to content

Instantly share code, notes, and snippets.

@raphael-brand
Last active April 21, 2017 15:08
Show Gist options
  • Save raphael-brand/028e112de0713bc414612d3291b0d6f5 to your computer and use it in GitHub Desktop.
Save raphael-brand/028e112de0713bc414612d3291b0d6f5 to your computer and use it in GitHub Desktop.
Fibonacci
class Fibonacci {
constructor(countUntil) {
this.a = 0;
this.b = 1;
this.c = 1;
this.r = [this.a, this.b];
if(countUntil) {
this.count = countUntil;
}
}
get result() {
return this.r;
}
set count(until) {
this.c = this.a + this.b
if(this.c < until) {
this.a = this.b
this.b = this.c
this.r.push(this.c)
this.count = until
}
}
}
f = new Fibonacci(200)
console.log(f.result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment