MCPcopy Create free account
hub / github.com/Effect-TS/effect / permutations

Function permutations

packages/effect/test/Hash.test.ts:29–42  ·  view source on GitHub ↗
(values: ReadonlyArray<A>)

Source from the content-addressed store, hash-verified

27}
28
29const permutations = <A>(values: ReadonlyArray<A>): ReadonlyArray<ReadonlyArray<A>> => {
30 const output: Array<ReadonlyArray<A>> = []
31 const visit = (prefix: ReadonlyArray<A>, remaining: ReadonlyArray<A>): void => {
32 if (remaining.length === 0) {
33 output.push(prefix)
34 return
35 }
36 for (let i = 0; i < remaining.length; i++) {
37 visit([...prefix, remaining[i]], [...remaining.slice(0, i), ...remaining.slice(i + 1)])
38 }
39 }
40 visit([], values)
41 return output
42}
43
44const assertNoHashCollisions = (values: Iterable<unknown>): void => {
45 const hashes = new Set<number>()

Callers 1

Hash.test.tsFile · 0.85

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected