Last active
July 5, 2019 10:49
-
-
Save andreyshedko/b0ed0e0970f5501b6daef090e4a76974 to your computer and use it in GitHub Desktop.
Flattening array
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 x = [[1,2,[3]],4]; | |
const flat = (arr) => { | |
if (Array.isArray(arr)) { | |
return arr.reduce((prev,curr) => { | |
return prev.concat(flat(curr)); | |
}, []); | |
} else { | |
return arr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment