Created
August 9, 2020 01:45
-
-
Save cplpearce/206c1ccc79166b57b8eae1da17e0bbb1 to your computer and use it in GitHub Desktop.
Kata 10 - The Great Codeville Bake-off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chooseRecipe = function(bakeryA, bakeryB, recipes) { | |
let applicableRecipies = ''; | |
for (let recipe of recipes) { | |
let boolBakeryA = false; | |
let boolBakeryB = false; | |
for (let ingredient of recipe.ingredients) { | |
bakeryA.includes(ingredient) && (boolBakeryA = true); | |
bakeryB.includes(ingredient) && (boolBakeryB = true); | |
} | |
(boolBakeryA && boolBakeryB) && (applicableRecipies += recipe.name); | |
boolBakeryA, boolBakeryB = false; | |
} | |
return (applicableRecipies); | |
} | |
let bakeryA = ['saffron', 'eggs', 'tomato paste', 'coconut', 'custard']; | |
let bakeryB = ['milk', 'butter', 'cream cheese']; | |
let recipes = [ | |
{ | |
name: 'Coconut Sponge Cake', | |
ingredients: ['coconut', 'cake base'] | |
}, | |
{ | |
name: 'Persian Cheesecake', | |
ingredients: ['saffron', 'cream cheese'] | |
}, | |
{ | |
name: 'Custard Surprise', | |
ingredients: ['custard', 'ground beef'] | |
} | |
]; | |
console.log(chooseRecipe(bakeryA, bakeryB, recipes)); | |
bakeryA = ['potatoes', 'bay leaf', 'raisins']; | |
bakeryB = ['red bean', 'dijon mustard', 'apples']; | |
recipes = [ | |
{ | |
name: 'Potato Ganache', | |
ingredients: ['potatoes', 'chocolate'] | |
}, | |
{ | |
name: 'Sweet Fish', | |
ingredients: ['anchovies', 'honey'] | |
}, | |
{ | |
name: "Nima's Famous Dijon Raisins", | |
ingredients: ['dijon mustard', 'raisins'] | |
} | |
]; | |
console.log(chooseRecipe(bakeryA, bakeryB, recipes)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment