function fib(max) { let t, a = 0, b = 1, arr = [a, b]; while (arr.length < max) { [a, b] = [b, a + b]; arr.push(b); } return arr; } fib(5); 结果: [0, 1, 1, 2, 3]