mdn for of

Solutions on MaxInterview for mdn for of by the best coders in the world

showing results for - "mdn for of"
Gaia
18 Mar 2017
1function* fibonacci() { // a generator function
2  let [prev, curr] = [0, 1];
3  while (true) {
4    [prev, curr] = [curr, prev + curr];
5    yield curr;
6  }
7}
8
9for (const n of fibonacci()) {
10  console.log(n);
11  // truncate the sequence at 1000
12  if (n >= 1000) {
13    break;
14  }
15}
16