(arr: T[], m: T[] = [])
| 49 | const result: ReadonlyArray<T>[] = []; |
| 50 | |
| 51 | const permute = (arr: T[], m: T[] = []) => { |
| 52 | if (arr.length === 0) { |
| 53 | if (!condition || condition(m)) { |
| 54 | // Use spread operator to create a shallow copy of m |
| 55 | result.push([...m]); |
| 56 | } |
| 57 | } else { |
| 58 | for (let i = 0; i < arr.length; i++) { |
| 59 | const curr = arr.slice(); |
| 60 | const next = curr.splice(i, 1); |
| 61 | permute(curr.slice(), m.concat(next)); |
| 62 | } |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | //@fix: (typing) |
| 67 | permute(xs as T[]); |