Last active
April 21, 2017 15:08
-
-
Save raphael-brand/028e112de0713bc414612d3291b0d6f5 to your computer and use it in GitHub Desktop.
Fibonacci
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 { | |
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