This content originally appeared on DEV Community and was authored by Calin Baenen
Here's how I'd respect someone's gender in TypeScript
/*
* A 3-bit number that represents the person's gender.
* (bits in the order of: MFT.)
* (MFT stands for "Male Female Trans".)
* (Special blends:
* 0x111 = Gender Fluid
* 0x110 = Bigender
* 0x001 = Nonbinary
* 0x000 = Agender
* )
* (
* Expansion upon this format is welcome. If you want
* to add more attributes, for more non-binary genders,
* feel free, and tell me your format below!
* )
*/
type Gender = number;
function sterilizeGenderId(g:Gender):Gender {
return g & 0b111; // 0b111 = 7.
}
class Person {
constructor(
name:String|string, age:number, gender:Gender
) {
this.gender = sterilizeGenderId(gender);
this.name = name;
this.age = age;
}
gender:Gender;
name:String|string;
age:number;
}
This content originally appeared on DEV Community and was authored by Calin Baenen
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Calin Baenen | Sciencx (2021-11-06T07:43:21+00:00) Respecting someone’s gender in a Person object.. Retrieved from https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/
" » Respecting someone’s gender in a Person object.." Calin Baenen | Sciencx - Saturday November 6, 2021, https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/
HARVARDCalin Baenen | Sciencx Saturday November 6, 2021 » Respecting someone’s gender in a Person object.., viewed ,<https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/>
VANCOUVERCalin Baenen | Sciencx - » Respecting someone’s gender in a Person object.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/
CHICAGO" » Respecting someone’s gender in a Person object.." Calin Baenen | Sciencx - Accessed . https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/
IEEE" » Respecting someone’s gender in a Person object.." Calin Baenen | Sciencx [Online]. Available: https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/. [Accessed: ]
rf:citation » Respecting someone’s gender in a Person object. | Calin Baenen | Sciencx | https://www.scien.cx/2021/11/06/respecting-someones-gender-in-a-person-object/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.