{"ScriptPreparationCode":"flattenArray = arr =\u003E {\r\n\treturn arr.reduce( (result, el) =\u003E {\r\n\t\treturn result.concat(\r\n\t\t\tArray.isArray(el) ? flattenArray(el) : el\r\n\t\t)\r\n\t}, []);\r\n}\r\n\r\nfunction baseFlatten(array, result) {\r\n\tvar index = -1,\r\n\t\tlength = array.length;\r\n\r\n\tresult || (result = []);\r\n\r\n\twhile (\u002B\u002Bindex \u003C length) {\r\n\t\tvar value = array[index];\r\n\t\tif (Array.isArray(value)) {\r\n\t\t\tbaseFlatten(value, result);\r\n\r\n\t\t} else {\r\n\t\t\tresult[result.length] = value;\r\n\t\t}\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nfunction flattenDeep(array) {\r\n\tvar length = array == null ? 0 : array.length;\r\n\treturn length ? baseFlatten(array) : [];\r\n}","TestCases":[{"Name":"first elegant","Code":"flattenArray([ 1, [ 2, [ 3 ] ], 4 ])","IsDeferred":false},{"Name":"second better","Code":"flattenDeep([ 1, [ 2, [ 3 ] ], 4 ])","IsDeferred":false}]}