Last active
April 22, 2022 11:41
-
-
Save fronterior/da605ac5190b9933b407b8bdf7376268 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* numberOfCases(...args) { | |
const stack = [[[], args]]; | |
while (stack.length) { | |
const target = stack.shift(); | |
if (target) { | |
const [result, rest] = target; | |
for (let i = 0; i < rest.length; i++) { | |
let r; | |
yield r = [...result, rest[i]]; | |
stack.push([r, rest.filter((_, index) => index !== i)]); | |
} | |
} | |
} | |
} | |
iter = numberOfCases(...'12345'.split('')); | |
[...iter]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment