Last active
February 25, 2022 22:27
-
-
Save fronterior/ab85970d66e6c3eda4ad044e4bc62e28 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 * backTracking(...args) { | |
const r = [[]]; | |
while (r.length) { | |
const t = r.shift(); | |
if (t.length === args.length) yield t; | |
else r.unshift(...args[t.length].map(i => [...t, i])); | |
} | |
} | |
const iter = backTracking([true, false], [1, 2, 3], [3, 4, 5, 6, 7], ['a', 'b'], ['c']); | |
[...iter]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment