-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterators-every.js
45 lines (36 loc) · 1.02 KB
/
iterators-every.js
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
// Iterators .every() Method
// The every() method tests whether all elements in the array pass the test
// implemented by the provided function. It returns a Boolean value.
const words = ['unique', 'uncanny', 'pique', 'oxymoron', 'guise'];
words.every(word => {
return word.length > 5;
}); // => false
function sourcePlant (food) {
if(food.source === 'plant') {
return true;
}
return false;
};
const isTheDinnerVegan = arr => {
if(arr.every(sourcePlant)) {
return true;
} else {
return false;
}
};
const dinner = [
{name: 'hamburger', source: 'meat'},
{name: 'cheese', source: 'dairy'},
{name: 'ketchup', source:'plant'},
{name: 'bun', source: 'plant'},
{name: 'dessert twinkies', source:'unknown'}
];
const veganDinner = [
{name: 'hamburger', source: 'plant'},
{name: 'cheese', source: 'plant'},
{name: 'ketchup', source:'plant'},
{name: 'bun', source: 'plant'},
{name: 'dessert twinkies', source:'plant'}
];
isTheDinnerVegan(dinner) // => false
isTheDinnerVegan(veganDinner) // => true