Created
August 15, 2023 06:40
-
-
Save arbaz52/61a879102e2a75b38677506af2730ec0 to your computer and use it in GitHub Desktop.
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 recursive = (input: string[][]): string[][] => { | |
if (input.length === 0) return []; | |
if (input.length === 1) return input[0].map((i) => [i]); | |
const arr = input[0]; | |
const perm = recursive(input.slice(1)); | |
const result = arr.map((a) => perm.map((p) => [a, ...p])).flat(1); | |
return result; | |
}; |
Author
arbaz52
commented
Aug 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment