-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbakeOff.js
More file actions
59 lines (54 loc) · 1.39 KB
/
bakeOff.js
File metadata and controls
59 lines (54 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const chooseRecipe = function(bakeryA, bakeryB, recipes) {
for(let recipe of recipes){
for(let search1 of recipe.ingredients){
if(findInside(search1, bakeryA)){
for(let search2 of recipe.ingredients){
if(findInside(search2, bakeryB)){
return recipe.name;
}
}
}
}
}
return false;
}
function findInside(item, array){ // auxiliary
for(let value of array){
if(item == value){return true}
}
return false;
}
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));