{"ScriptPreparationCode":"var isArray = Array.isArray;\r\nvar sourceArray = [1, [1, 2, [3, 4, [5, 6]]], 2, [3, 4, [1, 2, [3, [1, 2, [3, 4]], 4]], [5, 6, [1, 2, [3, 4, [5, 6]]], [7, 8, [9, 10]]]]];\r\n\r\nfunction flatPush(arr, depth) {\r\n if (depth === undefined) { depth = 100; } else if (depth \u003C= 0) { return arr; }\r\n var result = [];\r\n for (var len = arr.length, i = 0, val; i \u003C len; \u002B\u002Bi) {\r\n if (isArray((val = arr[i]))) {\r\n val = flatPush(val, depth - 1);\r\n for (var jen = val.length, j = 0; j \u003C jen; \u002B\u002Bj) { result.push(val[j]); }\r\n } else {\r\n result.push(val);\r\n }\r\n }\r\n return result;\r\n}\r\nfunction flatConcat(arr, depth) {\r\n if (depth === undefined) { depth = 100; } else if (depth \u003C= 0) { return arr; }\r\n var result = [];\r\n for (var len = arr.length, i = 0, val; i \u003C len; \u002B\u002Bi) {\r\n if (isArray((val = arr[i]))) {\r\n result = result.concat(flatConcat(val, depth - 1));\r\n } else {\r\n result.push(val);\r\n }\r\n }\r\n return result;\r\n}\r\nfunction flatSpread(arr, depth) {\r\n if (depth === undefined) { depth = 100; } else if (depth \u003C= 0) { return arr; }\r\n var result = [];\r\n for (var len = arr.length, i = 0, val; i \u003C len; \u002B\u002Bi) {\r\n if (isArray((val = arr[i]))) {\r\n result.push(...flatSpread(val, depth - 1));\r\n } else {\r\n result.push(val);\r\n }\r\n }\r\n return result;\r\n}","TestCases":[{"Name":"native flat","Code":"return sourceArray.flat(100);","IsDeferred":false},{"Name":"flatPush","Code":"return flatPush(sourceArray);","IsDeferred":false},{"Name":"flatConcat","Code":"return flatConcat(sourceArray);","IsDeferred":false},{"Name":"flatSpread","Code":"return flatSpread(sourceArray);","IsDeferred":false}]}