{"ScriptPreparationCode":"/*your preparation JavaScript code goes here\r\nTo execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/\r\nasync function globalMeasureThatScriptPrepareFunction() {\r\n // This function is optional, feel free to remove it.\r\n // await someThing();\r\n}\r\n\r\nfunction generateRandomTree(depth, maxChildren) {\r\n if (depth \u003C= 0) {\r\n return \u0060\u003Cspan\u003EData-${Math.random().toFixed(2)}\u003C/span\u003E\u0060;\r\n }\r\n\r\n const childrenCount = Math.floor(Math.random() * maxChildren) \u002B 1;\r\n const arr = [];\r\n\r\n arr.props = {\r\n id: Math.random()\r\n };\r\n arr.push(\u0060\u003Cdiv\u003E\u0060);\r\n\r\n for (let i = 0; i \u003C childrenCount; i\u002B\u002B) {\r\n if (Math.random() \u003E 0.2) {\r\n arr.push(generateRandomTree(depth - 1, maxChildren));\r\n } else {\r\n arr.push(\u0022text-node\u0022);\r\n }\r\n }\r\n\r\n arr.push(\u0060\u003C/div\u003E\u0060);\r\n\r\n return arr;\r\n}\r\n\r\n// Method A: Built-in Flat\r\nfunction renderFlat(tree) {\r\n return tree.flat(Infinity).join(\u0027\u0027);\r\n}\r\n\r\n// Method B: Custom Recursive Concatenation\r\nfunction renderRecursive(node) {\r\n if (typeof node === \u0027string\u0027) return node;\r\n if (Array.isArray(node)) {\r\n let str = \u0027\u0027;\r\n const len = node.length;\r\n for (let i = 0; i \u003C len; i\u002B\u002B) {\r\n str \u002B= renderRecursive(node[i]);\r\n }\r\n return str;\r\n }\r\n return \u0027\u0027;\r\n}\r\n\r\n// Method C: Custom iterative Concatenation\r\nfunction renderIterative(tree) {\r\n let html = \u0027\u0027;\r\n const stack = [tree];\r\n while (stack.length) {\r\n const node = stack.pop();\r\n if (typeof node === \u0027string\u0027) {\r\n html \u002B= node;\r\n continue;\r\n }\r\n\r\n if (Array.isArray(node)) {\r\n for (let i = node.length - 1; i \u003E= 0; i--) {\r\n stack.push(node[i]);\r\n }\r\n continue;\r\n }\r\n }\r\n\r\n return html;\r\n}\r\n\r\n// Method C: Custom iterative Concatenation\r\nfunction renderIterativeV2(tree) {\r\n let html = \u0027\u0027;\r\n const stack = [tree];\r\n while (stack.length) {\r\n const node = stack.pop();\r\n if (Array.isArray(node)) {\r\n for (let i = node.length - 1; i \u003E= 0; i--) {\r\n stack.push(node[i]);\r\n }\r\n continue;\r\n }\r\n\r\n html \u002B= node;\r\n\r\n }\r\n\r\n return html;\r\n}\r\n\r\nfunction renderIterativeV3(tree) {\r\n let html = \u0027\u0027;\r\n const stack = [tree];\r\n let stackIndex = 0;\r\n\r\n while (stackIndex \u003E= 0) {\r\n const node = stack[stackIndex];\r\n\r\n stackIndex--;\r\n\r\n if (typeof node === \u0027string\u0027) {\r\n html \u002B= node;\r\n continue;\r\n }\r\n\r\n if (Array.isArray(node)) {\r\n // Push children manually\r\n for (let i = node.length - 1; i \u003E= 0; i--) {\r\n stackIndex\u002B\u002B;\r\n stack[stackIndex] = node[i];\r\n }\r\n continue;\r\n }\r\n\r\n if (typeof node === \u0027number\u0027) {\r\n html \u002B= node;\r\n }\r\n }\r\n\r\n return html;\r\n}\r\n\r\nfunction renderIterativeV4(tree) {\r\n let html = \u0027\u0027;\r\n const stack = [tree];\r\n while (stack.length) {\r\n const node = stack.pop();\r\n if (typeof node === \u0027string\u0027) {\r\n html \u002B= node;\r\n continue;\r\n }\r\n\r\n for (let i = node.length - 1; i \u003E= 0; i--) {\r\n stack.push(node[i]);\r\n }\r\n }\r\n\r\n return html;\r\n}\r\n\r\nconst array = generateRandomTree(5, 10)","TestCases":[{"Name":"Array.flat().join()","Code":"const results = renderFlat(array)","IsDeferred":false},{"Name":"Recursive","Code":"const results = renderRecursive(array)","IsDeferred":false},{"Name":"Iterative","Code":"const results = renderIterative(array)","IsDeferred":false},{"Name":"Iterative v2","Code":"const results = renderIterativeV2(array)","IsDeferred":false},{"Name":"Iterative v3","Code":"const results = renderIterativeV3(array)","IsDeferred":false},{"Name":"Iterative v4","Code":"const results = renderIterativeV4(array)","IsDeferred":false}]}