-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filterExercises.js
54 lines (50 loc) · 1.38 KB
/
filterExercises.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
45
46
47
48
49
50
51
52
53
54
function fiveAndGreaterOnly(arr) {
return arr.filter(item => item >= 5);
}
// test
console.log(fiveAndGreaterOnly([3, 6, 8, 2])); /// [6, 8]
function evensOnly(arr) {
return arr.filter(item => item % 2 == 0);
}
// test
console.log(evensOnly([3, 6, 8, 2])); /// [6, 8, 2]
function fiveCharactersOrFewerOnly(arr) {
return arr.filter(item => item.length <= 5);
}
// test
console.log(
fiveCharactersOrFewerOnly(["dog", "wolf", "by", "family", "eaten", "camping"])
); // ["by", "dog", "wolf", "eaten"]
function peopleWhoBelongToTheIlluminati(arr) {
return arr.filter(person => person.member);
}
// test
console.log(
peopleWhoBelongToTheIlluminati([
{ name: "Angelina Jolie", member: true },
{ name: "Eric Jones", member: false },
{ name: "Paris Hilton", member: true },
{ name: "Kayne West", member: false },
{ name: "Bob Ziroll", member: true }
])
);
// =>
//[ { name: 'Angelina Jolie', member: true },
// { name: 'Paris Hilton', member: true },
// { name: 'Bob Ziroll', member: true } ]
function ofAge(arr) {
return arr.filter(person => person.age > 18);
}
// test
console.log(
ofAge([
{ name: "Angelina Jolie", age: 80 },
{ name: "Eric Jones", age: 2 },
{ name: "Paris Hilton", age: 5 },
{ name: "Kayne West", age: 16 },
{ name: "Bob Ziroll", age: 100 }
])
);
// =>
//[ { name: 'Angelina Jolie', age: 80 },
// { name: 'Bob Ziroll', age: 100 } ]