Created
January 2, 2020 10:31
-
-
Save kolyuchii/e40acaa9145fc0811076848866ede965 to your computer and use it in GitHub Desktop.
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
| function find(arr) { | |
| const maxDepth = arr.length - 1; | |
| const result = []; | |
| function helper(newArray, arrayIndex) { | |
| for (let i = 0; i < arr[arrayIndex].length; i += 1) { | |
| const arrCopy = newArray.slice(0); | |
| arrCopy.push(arr[arrayIndex][i]); | |
| if (arrayIndex === maxDepth) { | |
| result.push(arrCopy); | |
| } else { | |
| helper(arrCopy, arrayIndex + 1); | |
| } | |
| } | |
| } | |
| helper([], 0); | |
| return result; | |
| } | |
| find([[1,2], [3,4], [5,6]]) // [1,3,5] [1,3,6] [1,4,6] [2,3,5] [2,4,5] [2,4,6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment