problems(js): add “2648. Generate Fibonacci Sequence”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
6b53e90509
commit
85b9b28037
1 changed files with 17 additions and 0 deletions
17
problems/js/generate-fibonacci-sequence.js
Normal file
17
problems/js/generate-fibonacci-sequence.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* @return {Generator<number>}
|
||||
*/
|
||||
var fibGenerator = function*() {
|
||||
let a = 0, b = 1;
|
||||
|
||||
while (true) {
|
||||
yield a;
|
||||
[a, b] = [b, a + b];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* const gen = fibGenerator();
|
||||
* gen.next().value; // 0
|
||||
* gen.next().value; // 1
|
||||
*/
|
Loading…
Reference in a new issue