Created
June 27, 2017 04:38
-
-
Save guz-anton/a29048d25860769f77d9eabf09ffc502 to your computer and use it in GitHub Desktop.
A set of method to flatten arrays
This file contains hidden or 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 makeFlat = (array) => { | |
| return array.reduce((all, current) => { | |
| return Array.isArray(current) | |
| ? all.concat(makeFlat(current)) | |
| : all.push(current) && all; | |
| },[]); | |
| }; | |
| expect(makeFlat([[1,2,[3]],4])).toEqual([1,2,3,4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment