forked from jamesqquick/javascript-array-functions-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
40 lines (39 loc) · 971 Bytes
/
filter.js
File metadata and controls
40 lines (39 loc) · 971 Bytes
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
const characters = [
{
name: 'Luke Skywalker',
height: 172,
mass: 77,
eye_color: 'blue',
gender: 'male',
},
{
name: 'Darth Vader',
height: 202,
mass: 136,
eye_color: 'yellow',
gender: 'male',
},
{
name: 'Leia Organa',
height: 150,
mass: 49,
eye_color: 'brown',
gender: 'female',
},
{
name: 'Anakin Skywalker',
height: 188,
mass: 84,
eye_color: 'blue',
gender: 'male',
},
];
//***FILTER***
//1. Get characters with mass greater than 100
console.log(characters.filter(char=> char.mass >100))
//2. Get characters with height less than 200
console.log(characters.filter(char => char.height < 200))
//3. Get all male characters
console.log(characters.filter(char=> char.gender == "male"))
//4. Get all female characters
console.log(characters.filter(char => char.gender == "female"))