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

Version Path
trackler-2.2.1.180 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/allergies/allergies.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/allergies/allergies.example.ts