0 points

50% Probability with JS/TS (m/f example)


dashboard

Sat Nov 07 2020 23:04:05 GMT+0000 (UTC)

Posted by @narro #javascript #typescript

let rand = Math.random()
rand < 0.5 ? gender = 0 : gender = 1
this.name = `${gender ? '👩‍💼' : '👨‍💼'} ${faker.name.firstName(gender)} ${faker.name.lastName(gender)}`
content_copy Copy

This example was used when generating a male or female name with faker.js to indicate the emoji for that person with a 50% chance between male or female