{"ScriptPreparationCode":"const get = (depth = 0) =\u003E {\r\n const arr = [];\r\n if (depth \u003E 100) { // Stop recursion beyond depth 2\r\n return arr; // Return an empty array to avoid undefined entries\r\n }\r\n for (let i = 0; i \u003C 10; i\u002B\u002B) { // Reduced loop count for demonstration\r\n if (Math.random() \u003E 0.2) {\r\n // Recursively call get(), but wrap the result in an array to ensure arrays are nested within\r\n arr.push([get(depth \u002B 1)]);\r\n } else {\r\n // Create a sub-array of numbers\r\n const numberArray = [];\r\n for (let j = 0; j \u003C 100; j\u002B\u002B) {\r\n numberArray.push(Math.floor(Math.random() * 100));\r\n }\r\n // Decide randomly to push the whole array or individual numbers\r\n if (Math.random() \u003E 0.5) {\r\n arr.push(numberArray); // Push the array as a single element\r\n } else {\r\n arr.push(...numberArray); // Spread the array into individual elements\r\n }\r\n }\r\n }\r\n return arr;\r\n};\r\n\r\nvar array = get(99)","TestCases":[{"Name":"reduce","Code":"const flatten = (arr) =\u003E \r\n arr.reduce((acc, x) =\u003E {\r\n Array.isArray(x) ? flatten(x).forEach(y =\u003E acc.push(y)) : acc.push(x)\r\n return acc;\r\n }, [])\r\n\r\n\r\nconst x = flatten(array);\r\n","IsDeferred":false},{"Name":"for of","Code":"const flat = (argarr) =\u003E {\r\n let arr = []\r\n for (const item of argarr) {\r\n if (Array.isArray(item)) arr = arr.concat(flat(item))\r\n else arr.push(item)\r\n }\r\n return arr\r\n}\r\n\r\n\r\nconst x = flat(array);\r\n","IsDeferred":false},{"Name":"reduce TOC","Code":"const flatten = (arr, acc = []) =\u003E {\r\n arr.forEach(x =\u003E {\r\n if (Array.isArray(x)) {\r\n flatten(x, acc);\r\n } else {\r\n acc.push(x);\r\n }\r\n });\r\n return acc;\r\n};\r\n\r\nconst x = flatten(array);\r\n\r\n","IsDeferred":false}]}