const getLeaderBoard = (students) => {
students.forEach(student => {
student.totalGrade = student.grades.english + student.grades.physics + student.grades.math + student.grades.programming
});
const topStudents = students
.filter(student => student.totalGrade >= 85)
.sort((a,b)=> b.totalGrade - a.totalGrade)
return topStudents;
}
const students = [
{
name: '3bkreem',
class: '3rd',
grades: {
math: 25,
physics: 25,
programming: 25,
english: 25
}
},
{
name: 'Samer',
class: '3rd',
grades: {
math: 10,
physics: 15,
programming: 12,
english: 19
}
},
{
name: 'Ahmed',
class: '3rd',
grades: {
math: 20,
physics: 20,
programming: 20,
english: 20
}
},
{
name: 'Ali',
class: '3rd',
grades: {
math: 20,
physics: 25,
programming: 19,
english: 22
}
},
{
name: 'Elgoker',
class: '3rd',
grades: {
math: 23,
physics: 25,
programming: 19,
english: 22
}
}
]
console.log(getLeaderBoard(students));
console.log(students);
Y29uc3QgZ2V0TGVhZGVyQm9hcmQgPSAoc3R1ZGVudHMpID0+IHsKICAgIHN0dWRlbnRzLmZvckVhY2goc3R1ZGVudCA9PiB7CiAgICAgICBzdHVkZW50LnRvdGFsR3JhZGUgPSBzdHVkZW50LmdyYWRlcy5lbmdsaXNoICsgc3R1ZGVudC5ncmFkZXMucGh5c2ljcyArIHN0dWRlbnQuZ3JhZGVzLm1hdGggKyBzdHVkZW50LmdyYWRlcy5wcm9ncmFtbWluZwogICAgICAgCiAgICB9KTsKICAgIGNvbnN0IHRvcFN0dWRlbnRzID0gc3R1ZGVudHMKICAgIC5maWx0ZXIoc3R1ZGVudCA9PiBzdHVkZW50LnRvdGFsR3JhZGUgPj0gODUpCiAgICAuc29ydCgoYSxiKT0+IGIudG90YWxHcmFkZSAtIGEudG90YWxHcmFkZSkKICAgIHJldHVybiB0b3BTdHVkZW50czsKICB9CiAgCiAgCiAgY29uc3Qgc3R1ZGVudHMgPSBbCiAgICB7CiAgICAgIG5hbWU6ICczYmtyZWVtJywKICAgICAgY2xhc3M6ICczcmQnLAogICAgICBncmFkZXM6IHsKICAgICAgICBtYXRoOiAyNSwKICAgICAgICBwaHlzaWNzOiAyNSwKICAgICAgICBwcm9ncmFtbWluZzogMjUsCiAgICAgICAgZW5nbGlzaDogMjUKICAgICAgfQogICAgfSwKICAKICAgIHsKICAgICAgbmFtZTogJ1NhbWVyJywKICAgICAgY2xhc3M6ICczcmQnLAogICAgICBncmFkZXM6IHsKICAgICAgICBtYXRoOiAxMCwKICAgICAgICBwaHlzaWNzOiAxNSwKICAgICAgICBwcm9ncmFtbWluZzogMTIsCiAgICAgICAgZW5nbGlzaDogMTkKICAgICAgfQogICAgfSwKICAKICAgIHsKICAgICAgbmFtZTogJ0FobWVkJywKICAgICAgY2xhc3M6ICczcmQnLAogICAgICBncmFkZXM6IHsKICAgICAgICBtYXRoOiAyMCwKICAgICAgICBwaHlzaWNzOiAyMCwKICAgICAgICBwcm9ncmFtbWluZzogMjAsCiAgICAgICAgZW5nbGlzaDogMjAKICAgICAgfQogICAgfSwKICAKICAgIHsKICAgICAgbmFtZTogJ0FsaScsCiAgICAgIGNsYXNzOiAnM3JkJywKICAgICAgZ3JhZGVzOiB7CiAgICAgICAgbWF0aDogMjAsCiAgICAgICAgcGh5c2ljczogMjUsCiAgICAgICAgcHJvZ3JhbW1pbmc6IDE5LAogICAgICAgIGVuZ2xpc2g6IDIyCiAgICAgIH0KICAgIH0sCiAgCiAgICB7CiAgICAgIG5hbWU6ICdFbGdva2VyJywKICAgICAgY2xhc3M6ICczcmQnLAogICAgICBncmFkZXM6IHsKICAgICAgICBtYXRoOiAyMywKICAgICAgICBwaHlzaWNzOiAyNSwKICAgICAgICBwcm9ncmFtbWluZzogMTksCiAgICAgICAgZW5nbGlzaDogMjIKICAgICAgfQogICAgfQogIF0KCiAgY29uc29sZS5sb2coZ2V0TGVhZGVyQm9hcmQoc3R1ZGVudHMpKTsKICBjb25zb2xlLmxvZyhzdHVkZW50cyk7Cg==