mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
7919c9a7eb
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DanielRosenwasser <[email protected]> Co-authored-by: Daniel Rosenwasser <[email protected]>
40 lines
684 B
TypeScript
40 lines
684 B
TypeScript
// @strict: true
|
|
// @noEmit: true
|
|
|
|
class A {
|
|
next: A | null = null;
|
|
|
|
constructor(readonly children: (A | null)[]) {}
|
|
}
|
|
|
|
function getNodes(): A[] {
|
|
const out: A[] = [];
|
|
|
|
let current: A | null = new A([]);
|
|
|
|
while (current !== null) {
|
|
let firstChild = null;
|
|
|
|
if (out.length) {
|
|
current = current.next;
|
|
continue;
|
|
}
|
|
|
|
for (let i = 0; i < current.children.length; i++) {
|
|
const child = current.children[i];
|
|
|
|
if (child) {
|
|
if (!firstChild) {
|
|
firstChild = child;
|
|
firstChild.next = current.next;
|
|
}
|
|
|
|
child.next = current.next;
|
|
}
|
|
}
|
|
|
|
current = firstChild || current.next;
|
|
}
|
|
|
|
return out;
|
|
} |