new class js -advanced
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
const isMixableWithMyIngredients = (cocktailRecipe) =>
|
||||
isMixableWith(cocktailRecipe, ingredientsFromMyBar);
|
||||
|
||||
const isMixableWith = (cocktailRecipe, availableIngredients) =>
|
||||
cocktailRecipe.every((ingredientFromRecipe) =>
|
||||
hasIngredient(availableIngredients, ingredientFromRecipe)
|
||||
);
|
||||
|
||||
const hasIngredient = (listOfIngredients, searchedIngredient) =>
|
||||
listOfIngredients.includes(searchedIngredient);
|
||||
|
||||
const honoluluFlip = [
|
||||
'Maracuja Juice',
|
||||
'Pineapple Juice',
|
||||
'Lemon Juice',
|
||||
'Grapefruit Juice',
|
||||
'Crushed Ice',
|
||||
];
|
||||
const casualFriday = ['Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber'];
|
||||
|
||||
const pinkDolly = [
|
||||
'Vodka',
|
||||
'Orange Juice',
|
||||
'Pineapple Juice',
|
||||
'Grenadine',
|
||||
'Cream',
|
||||
'Coco Syrup',
|
||||
];
|
||||
const cocktailRecipes = [honoluluFlip, casualFriday, pinkDolly];
|
||||
|
||||
const ingredientsFromMyBar = [
|
||||
'Pineapple',
|
||||
'Maracuja Juice',
|
||||
'Cream',
|
||||
'Grapefruit Juice',
|
||||
'Crushed Ice',
|
||||
'Milk',
|
||||
'Vodka',
|
||||
'Apple Juice',
|
||||
'Aperol',
|
||||
'Pineapple Juice',
|
||||
'Lime Juice',
|
||||
'Lemons',
|
||||
'Cucumber',
|
||||
];
|
||||
|
||||
console.log(cocktailRecipes.find(isMixableWithMyIngredients));
|
||||
// => [ 'Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber' ]
|
||||
Reference in New Issue
Block a user