Skip to content

Instantly share code, notes, and snippets.

@deng232
deng232 / permu.ts
Last active April 22, 2024 03:27
ts/js short Heap's algorithm for strings permutation
const permutations = (combo: string[]): string[][] => {
// combo[]
return combo
.map((v, i, combo) => {
const right = [...combo]
const left = right.splice(i, 1)[0] // remove and return index from array;
if (right.length === 0) {
return [[left]]
}