Last active
December 6, 2016 19:30
-
-
Save Qrysto/5230bcaff322ca0c87c52daf4a9abbc2 to your computer and use it in GitHub Desktop.
Requirement: "Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]. Your solution should be a link to a gist on gist.github.com with your implementation. When writing this code, you can use any language you're comfortable with. The code must be well te…
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
| // Written in Javascript (ES2015) | |
| const flatten = arg => | |
| typeof arg === 'number' ? [arg] : | |
| typeof arg === 'object' && Array.isArray(arg) ? | |
| arg.reduce( | |
| (result, element) => result.concat(flatten(element)) | |
| , []) : | |
| []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment