{ "data": { "question": { "questionId": "2775", "questionFrontendId": "2648", "categoryTitle": "JavaScript", "boundTopicId": 2238333, "title": "Generate Fibonacci Sequence", "titleSlug": "generate-fibonacci-sequence", "content": "
Write a generator function that returns a generator object which yields the fibonacci sequence.
\n\nThe fibonacci sequence is defined by the relation Xn = Xn-1 + Xn-2
.
The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, 13
.
\n
Example 1:
\n\n\nInput: callCount = 5\nOutput: [0,1,1,2,3]\nExplanation:\nconst gen = fibGenerator();\ngen.next().value; // 0\ngen.next().value; // 1\ngen.next().value; // 1\ngen.next().value; // 2\ngen.next().value; // 3\n\n\n
Example 2:
\n\n\nInput: callCount = 0\nOutput: []\nExplanation: gen.next() is never called so nothing is outputted\n\n\n
\n
Constraints:
\n\n0 <= callCount <= 50
请你编写一个生成器函数,并返回一个可以生成 斐波那契数列 的生成器对象。
\n\n斐波那契数列 的递推公式为 Xn = Xn-1 + Xn-2
。
这个数列的前几个数字是 0, 1, 1, 2, 3, 5, 8, 13
。
\n\n
示例 1:
\n\n\n输入:callCount = 5\n输出:[0,1,1,2,3]\n解释:\nconst gen = fibGenerator();\ngen.next().value; // 0\ngen.next().value; // 1\ngen.next().value; // 1\ngen.next().value; // 2\ngen.next().value; // 3\n\n\n
示例 2:
\n\n\n输入:callCount = 0\n输出:[]\n解释:gen.next() 永远不会被调用,所以什么也不会输出\n\n\n
\n\n
提示:
\n\n0 <= callCount <= 50
\\u7248\\u672c\\uff1a \\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\" TypeScript 4.5.4<\\/p>\\r\\n\\r\\n Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "5\n0",
"__typename": "QuestionNode"
}
}
}Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n
--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n