Skip to content

Instantly share code, notes, and snippets.

@fronterior
Last active February 25, 2022 22:27
Show Gist options
  • Save fronterior/ab85970d66e6c3eda4ad044e4bc62e28 to your computer and use it in GitHub Desktop.
Save fronterior/ab85970d66e6c3eda4ad044e4bc62e28 to your computer and use it in GitHub Desktop.
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