Allergies

This commit is contained in:
2025-04-18 21:39:46 +02:00
parent 96bd169f8b
commit b7199d2a17
21 changed files with 33484 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
const allergenMap = {
eggs: 1,
peanuts: 2,
shellfish: 4,
strawberries: 8,
tomatoes: 16,
chocolate: 32,
pollen: 64,
cats: 128,
} as const
type Allergen = keyof typeof allergenMap
export class Allergies {
constructor(private _allergenIndex: number) {}
public list(): Allergen[] {
return Object.entries(allergenMap)
.filter(([_, weight]) => (this._allergenIndex & weight) !== 0)
.map(([allergen]) => allergen as Allergen)
}
public allergicTo(allergen: Allergen): boolean {
return this.list().includes(allergen)
}
}