Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
// Recursive types (runtime illustration) // Binary tree type Node
= { value: T; left?: Node
; right?: Node
}; const tree: Node
= { value: 2, left: { value: 1 }, right: { value: 3 }, }; function preorder
(n?: Node
, acc: T[] = []): T[] { if (!n) return acc; acc.push(n.value); preorder(n.left, acc); preorder(n.right, acc); return acc; } console.log(preorder(tree).join(" ")); // JSON-like data const jsonLike = { a: 1, b: [true, null], c: { d: "x" } }; console.log(JSON.stringify(jsonLike));
2 1 3 {"a":1,"b":[true,null],"c":{"d":"x"}}