Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 9, 2020 01:45
Show Gist options
  • Save cplpearce/206c1ccc79166b57b8eae1da17e0bbb1 to your computer and use it in GitHub Desktop.
Save cplpearce/206c1ccc79166b57b8eae1da17e0bbb1 to your computer and use it in GitHub Desktop.
Kata 10 - The Great Codeville Bake-off
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