( digits: string[], rng: () => number )
| 54 | } |
| 55 | |
| 56 | export 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 | |
| 78 | export function isAllSame(code: string): boolean { |
| 79 | if (!code) return false |
no test coverage detected