Created
August 24, 2020 10:51
-
-
Save denniskigen/dcb7b206e5d25bc895601765b160f5ff to your computer and use it in GitHub Desktop.
This file contains 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 implements IterableIterator<number> { | |
protected f1 = 0; | |
protected f2 = 1; | |
constructor(protected maxValue?: number) {} | |
public next(): IteratorResult<number> { | |
if (this.maxValue != null && current >= this.maxValue) { | |
return { | |
done: true, | |
value: null | |
} | |
} | |
return { | |
done: false, | |
value: null | |
} | |
} | |
[Symbol.iterator](): IterableIterator<number> { | |
return this; | |
} | |
} | |
let fibMax1000 = new Fibonacci(1000); | |
Array.from(fibMax1000) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment