-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExerciseArray1.js
More file actions
93 lines (78 loc) · 1.91 KB
/
ExerciseArray1.js
File metadata and controls
93 lines (78 loc) · 1.91 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const character=[{
name:"Tarak Matha",
height:"172",
mass:"77",
eye_color:"Brown",
gender:"male"
},
{
name:"JethaLal",
height:"145",
mass:"136",
eye_color:"Black",
gender:"male"
},
{
name:"Babita Ji",
height:"150",
mass:"49",
eye_color:"grey",
gender:"female"
},
{
name:"Himesh reshmia",
height:"168",
mass:"84",
eye_color:"Black",
gender:"male"
},];
//get an array of all names
const Name=character.map(person=> person.name)
// console.log(Name)
//get an arry of objects with name and height properties
const Prop1=character.map(ch =>{
// console.log({name:ch.name, height:ch.height})
})
//get the total height of all character
const TotalH=character.reduce((perviousHeight,character)=>
{
return perviousHeight+Number(character.height)
},0);
// console.log(TotalH);
//get character with mass greater then 100
MassCh=character.filter(element => Number(element.mass)>100)
// console.log(MassCh);
//get all male characters
gendrCh=character.filter(ch=>ch.gender=='male')
// console.log(gendrCh);
//sort by gender
sortGender=character.sort((ch1,ch2)=>{
if(ch1.gender>ch2.gender) {
return -1
}
if(ch1.gender<ch2.gender){
return 1
}
return 0
})
// console.log(sortGender);
//sort by name
sortName=character.sort((ch1,ch2) => {
if(ch1.name<ch2.name){
return -1;
}
if (ch1.name>ch2.name){
return 1;
}
return 0;
});
// console.log(sortName);
//does every character have mass more than 40?
const ChCheck=character.every(ch1 =>ch1.mass>40);
// console.log(ChCheck);
//does every character have blue eyes
// console.log(character.every(ch => ch.eye_color==="Blue"));
//Is there atlist one male character
// console.log(character.some(ch => ch.gender ==="male"));
//is there one character with height greater then 200?
console.log(character.some(ch => Number(ch.height) > 200));