Initial data
_30const scores = [_30 {_30 marks: 32,_30 name: "Yvette Merritt",_30 },_30 {_30 marks: 57,_30 name: "Lillian Ellis",_30 },_30 {_30 marks: 22,_30 name: "Mccall Carter",_30 },_30 {_30 marks: 21,_30 name: "Pate Collier",_30 },_30 {_30 marks: 91,_30 name: "Debra Beard",_30 },_30 {_30 marks: 75,_30 name: "Nettie Hancock",_30 },_30 {_30 marks: 20,_30 name: "Hatfield Hodge",_30 },_30];
Use the above data to answer all the below tasks
Task I
Print the name list - as an array
Expected Output I
_9[_9 "Yvette Merritt",_9 "Lillian Ellis",_9 "Mccall Carter",_9 "Pate Collier",_9 "Debra Beard",_9 "Nettie Hancock",_9 "Hatfield Hodge",_9];
Answer
_1scores.map(({ name }) => name);
Task II
Criteria for passing >=40
.
Find those students that passed test.
Expected Output II
_14[_14 {_14 marks: 57,_14 name: "Lillian Ellis",_14 },_14 {_14 marks: 91,_14 name: "Debra Beard",_14 },_14 {_14 marks: 75,_14 name: "Nettie Hancock",_14 },_14];
Answer
_1scores.filter(({ marks }) => marks >= 40);
Task III
Find all the names who failed the exams
Expected Output III
_1["Yvette Merritt", "Mccall Carter", "Pate Collier", "Hatfield Hodge"];
Answer
_1scores.filter(({ marks }) => marks < 40).map(({ name }) => name);
Task IV
Find the Average marks
Answer
_3const total = scores.reduce((sum, { marks }) => sum + marks, 0);_3_3console.log(total, total / scores.length);
Task V
Find the topper's name
Expected Output V
_1"Debra Beard";
Answer
_5const topper = scores.reduce((topper, student) =>_5 topper.marks < student.marks ? student : topper_5);_5_5console.log(topper.name);
@ragavkumarv
swipe to next โก๏ธ