Skip to content

Instantly share code, notes, and snippets.

@fronterior
Created December 24, 2021 12:22
Show Gist options
  • Save fronterior/32d4729b2a7a6efb1642ece8f182e3bb to your computer and use it in GitHub Desktop.
Save fronterior/32d4729b2a7a6efb1642ece8f182e3bb to your computer and use it in GitHub Desktop.
const args = [
[1,2,3],
[1],
['a', 'b'],
['c', 'd', 'e'],
[5],
];
const r = [[]] as any;
let i = 0;
while (i++ !== args.length) {
const s = [];
while (r.length) {
const t = r.shift();
if (t.length < args.length) {
args[t.length].map(i => s.push([...t, i]));
}
}
r.push(...s);
}
console.log(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment