MCPcopy Index your code
hub / github.com/TeaCoder52/patcode / pickThreeDifferentDigits

Function pickThreeDifferentDigits

src/utils.ts:56–76  ·  view source on GitHub ↗
(
	digits: string[],
	rng: () => number
)

Source from the content-addressed store, hash-verified

54}
55
56export function pickThreeDifferentDigits(
57 digits: string[],
58 rng: () => number
59): [string, string, string] {
60 if (digits.length < 3) throw new Error('Need at least 3 different digits')
61
62 const [d1, d2] = pickTwoDifferentDigits(digits, rng)
63 let d3 = pickDigit(digits, rng)
64 let guard = 0
65
66 while ((d3 === d1 || d3 === d2) && guard++ < 30) {
67 d3 = pickDigit(digits, rng)
68 }
69
70 if (d3 === d1 || d3 === d2) {
71 const filtered = digits.filter((d) => d !== d1 && d !== d2)
72 d3 = pickDigit(filtered, rng)
73 }
74
75 return [d1, d2, d3]
76}
77
78export function isAllSame(code: string): boolean {
79 if (!code) return false

Callers 1

createCustomContextFunction · 0.90

Calls 2

pickTwoDifferentDigitsFunction · 0.85
pickDigitFunction · 0.85

Tested by

no test coverage detected