任何人都可以向我解释这段代码中的 i++ 和 y++ 区域主要是其他部分,因为我只是不明白为了得到结果发生了什么

Can anyone explain to me this code the i++ and y++ areas mostly the else part cause I just can't understand what's happening to get the result

这是执行斐波那契生成器的代码。我不明白 i++ 和 y++ 在做什么,以及这一切是如何给我们提供序列的。 :(

function fibonacciGenerator(n) {
  var fib = [0, 1];
  var i = 0;
  var y = 1;

  if (n === 1) {
    fib.pop();
  } else {
    for (var i = 0; fib.length < n; i++) {
      fib.push(fib[i] + fib[y]);
      y++;
    }
  }
  return fib;
}

i 总是 fib.length - 2,y 总是 fib.length - 1。每次迭代都会增加数组的大小,所以这两个计数器必须递增以始终指向最后两个插槽。