Created
July 19, 2016 21:19
-
-
Save thaerlabs/0defea809dd5bddb64546758f8595e71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = [[1,2,[3]],4]; | |
function arrFlatten() { | |
let flat = []; | |
for (let i = 0; i < arguments.length; i++) { | |
if (arguments[i] instanceof Array) { | |
flat.push.apply(flat, arrFlatten.apply(this, arguments[i])); | |
} else { | |
flat.push(arguments[i]); | |
} | |
} | |
return flat; | |
} | |
console.log(arrFlatten(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment