Sha256: 5a0d67fa9d51882d0df76e6d1c40df404a46900d9c0d44d926593f1c9c6124b2
Contents?: true
Size: 875 Bytes
Versions: 68
Compression:
Stored size: 875 Bytes
Contents
class Allergies { allergenIndex: number possibleAllergies = [ 'eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats' ] constructor(allergenIndex: number) { this.allergenIndex = allergenIndex } allergicTo(food: string) { let isAllergic = false const allergyList = this.list() for (const allergy of allergyList) { if (allergy === food) { isAllergic = true break } } return isAllergic } list(): string[] { const possibleAllergies = this.possibleAllergies const allergicTo = [] for (let i = 0; i < possibleAllergies.length; i++) { const allergy = possibleAllergies[i] if (this.allergenIndex & Math.pow(2, i)) { allergicTo.push(allergy) } } return allergicTo } } export default Allergies
Version data entries
68 entries across 68 versions & 1 rubygems