(userId: string)
| 8 | * @returns 'A' or 'B' based on the hash. |
| 9 | */ |
| 10 | export function assignVariantBucket(userId: string): 'A' | 'B' { |
| 11 | // Create a hash of the userId |
| 12 | const hash = crypto.createHash('sha256').update(userId).digest('hex'); |
| 13 | |
| 14 | // Convert first character of hash to a number (0-15 in hex) |
| 15 | // Use modulo 2 to determine bucket A or B |
| 16 | const numericValue = parseInt(hash.charAt(0), 16); |
| 17 | |
| 18 | return numericValue % 2 === 0 ? 'A' : 'B'; |
| 19 | } |
no outgoing calls
no test coverage detected