dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
71 lines
2.8 KiB
Markdown
71 lines
2.8 KiB
Markdown
---
|
|
id: 69cfca90e8a0a6d4d6871c53
|
|
title: "Challenge 269: Allergen Friendly Meals"
|
|
challengeType: 29
|
|
dashedName: challenge-269
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given an array of meals and an array of allergens to avoid, return the names of all the meals that contain none of the given allergens.
|
|
|
|
- Each meal is in the format `[meal, allergens]`, where `meal` is the name of the meal, and `allergens` is an array of the allergens the meal contains. For example, `["pasta", ["wheat", "milk"]]`.
|
|
- Allergens to avoid will be an array of strings.
|
|
|
|
Return safe meal names in the same order given. If no meal is safe, return an empty array.
|
|
|
|
# --hints--
|
|
|
|
`get_allergen_friendly_meals([["pasta", ["wheat", "milk"]], ["salad", ["nuts"]]], ["milk"])` should return `["salad"]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_allergen_friendly_meals([["pasta", ["wheat", "milk"]], ["salad", ["nuts"]]], ["milk"]), ["salad"])`)
|
|
}})
|
|
```
|
|
|
|
`get_allergen_friendly_meals([["steak", ["soy"]], ["fried rice", []], ["fish tacos", ["fish", "wheat"]], ["chicken parmesan", ["wheat", "milk"]]], ["soy", "fish"])` should return `["fried rice", "chicken parmesan"]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_allergen_friendly_meals([["steak", ["soy"]], ["fried rice", []], ["fish tacos", ["fish", "wheat"]], ["chicken parmesan", ["wheat", "milk"]]], ["soy", "fish"]), ["fried rice", "chicken parmesan"])`)
|
|
}})
|
|
```
|
|
|
|
`get_allergen_friendly_meals([["oatmeal", ["nuts"]], ["pancakes", ["wheat", "milk"]], ["granola", []], ["yogurt", ["milk"]], ["eggs", ["eggs", "milk"]], ["toast", ["wheat"]]], ["eggs", "milk"])` should return `["oatmeal", "granola", "toast"]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_allergen_friendly_meals([["oatmeal", ["nuts"]], ["pancakes", ["wheat", "milk"]], ["granola", []], ["yogurt", ["milk"]], ["eggs", ["eggs", "milk"]], ["toast", ["wheat"]]], ["eggs", "milk"]), ["oatmeal", "granola", "toast"])`)
|
|
}})
|
|
```
|
|
|
|
`get_allergen_friendly_meals([["oatmeal", ["nuts"]], ["pancakes", ["wheat", "milk"]], ["granola", []], ["yogurt", ["milk"]], ["eggs", ["eggs", "milk"]], ["toast", ["wheat"]]], ["wheat", "nuts"])` should return `["granola", "yogurt", "eggs"]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_allergen_friendly_meals([["oatmeal", ["nuts"]], ["pancakes", ["wheat", "milk"]], ["granola", []], ["yogurt", ["milk"]], ["eggs", ["eggs", "milk"]], ["toast", ["wheat"]]], ["wheat", "nuts"]), ["granola", "yogurt", "eggs"])`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def get_allergen_friendly_meals(meals, allergens):
|
|
|
|
return meals
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def get_allergen_friendly_meals(meals, allergens):
|
|
return [name for name, meal_allergens in meals if not any(a in meal_allergens for a in allergens)]
|
|
```
|