MCPcopy
hub / github.com/freeCodeCamp/freeCodeCamp / assignVariantBucket

Function assignVariantBucket

api/src/utils/drip-campaign.ts:10–19  ·  view source on GitHub ↗
(userId: string)

Source from the content-addressed store, hash-verified

8 * @returns 'A' or 'B' based on the hash.
9 */
10export 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}

Callers 3

findOrCreateUserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected