Skip to content

Commit 0697388

Browse files
committed
Update index.ts
1 parent 4c6edf5 commit 0697388

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

flatten-nested-list-iterator/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@
3838
*/
3939

4040
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-
}
41+
function* NestedIntegerIterator(
42+
nestedList: NestedInteger[],
43+
): Generator<number | null, void, unknown> {
44+
for (const nestedInteger of nestedList) {
4845
if (nestedInteger.isInteger()) {
4946
yield nestedInteger.getInteger();
5047
} else {
51-
nestedList.unshift(...nestedInteger.getList());
48+
yield* NestedIntegerIterator(nestedInteger.getList());
5249
}
5350
}
5451
}

0 commit comments

Comments
 (0)