Created
June 15, 2016 01:53
-
-
Save jafow/4e358edf566bc9c6a567e83c08c87fbd to your computer and use it in GitHub Desktop.
divorce
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
/** | |
* divorce takes an array of nested array pairs and returns 2 one-dimensional arrays with elements from each pair, in order | |
* ex: divorce([[1,2], [3,4]]) --> {a1: [1,3], a2: [2,4]} | |
*/ | |
const divorce = (arr, a1 = [], a2 = []) => | |
!arr[0] | |
? { a1, a2 } | |
: divorce(arr.slice(1), a1.concat(arr[0][0]), a2.concat(arr[0][1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment