forked from bhubr/array-map-filter
-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathex2.js
More file actions
63 lines (50 loc) · 1.52 KB
/
ex2.js
File metadata and controls
63 lines (50 loc) · 1.52 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
60
61
62
63
/* Array.prototype.map - Exercise 2
* Write the CONTENTS of the `getFoodCategories` function
* It receives an array of OBJECTS as an argument
* Each object in this array has two attributes:
`food` is the name of a food product
`isVegetarian` is a boolean, indicating if this product is suitable for vegetarians
* Using map, `getFoodCategories` must return an array of STRINGS.
* For each element (object) of the input `foods` array, the corresponding element in the
output array can be computed this way:
* "FOOD is suitable for vegetarians" if the `isVegetarian` attribute is true
* "FOOD is not suitable for vegetarians" if the `isVegetarian` attribute is false
(replace FOOD with the `food` attribute)
Sample foods array, i.e. INPUT:
[
{
food: 'Bacon',
isVegetarian: false
},
{
food: 'Sausage',
isVegetarian: false
},
{
food: 'Tofu',
isVegetarian: true
},
{
food: 'Chick Pea',
isVegetarian: true
}
]
Expected OUTPUT for this sample
[
'Bacon is not suitable for vegetarians',
'Sausage is not suitable for vegetarians',
'Tofu is suitable for vegetarians',
'Chick Pea is suitable for vegetarians'
]
*/
function getFoodCategories(foods) {
return foods.map(aliment => {
if (aliment.isVegetarian === true){
return (aliment.food + ' is suitable for vegetarians')
} else {
return (aliment.food + ' is not suitable for vegetarians')
}
})
}
// DON'T TOUCH THIS!
module.exports = getFoodCategories;