We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4c6edf5 commit 0697388Copy full SHA for 0697388
flatten-nested-list-iterator/index.ts
@@ -38,17 +38,14 @@
38
*/
39
40
import { NestedInteger } from "../mini-parser/NestedInteger.ts";
41
-function* NestedIntegerIterator(nestedList: NestedInteger[]) {
42
- nestedList = Array.from(nestedList);
43
- while (nestedList.length) {
44
- const nestedInteger = nestedList.shift();
45
- if (!nestedInteger) {
46
- return;
47
- }
+function* NestedIntegerIterator(
+ nestedList: NestedInteger[],
+): Generator<number | null, void, unknown> {
+ for (const nestedInteger of nestedList) {
48
if (nestedInteger.isInteger()) {
49
yield nestedInteger.getInteger();
50
} else {
51
- nestedList.unshift(...nestedInteger.getList());
+ yield* NestedIntegerIterator(nestedInteger.getList());
52
}
53
54
0 commit comments