fork download
  1. const getLeaderBoard = (students) => {
  2. students.forEach(student => {
  3. student.totalGrade = student.grades.english + student.grades.physics + student.grades.math + student.grades.programming
  4.  
  5. });
  6. const topStudents = students
  7. .filter(student => student.totalGrade >= 85)
  8. .sort((a,b)=> b.totalGrade - a.totalGrade)
  9. return topStudents;
  10. }
  11.  
  12.  
  13. const students = [
  14. {
  15. name: '3bkreem',
  16. class: '3rd',
  17. grades: {
  18. math: 25,
  19. physics: 25,
  20. programming: 25,
  21. english: 25
  22. }
  23. },
  24.  
  25. {
  26. name: 'Samer',
  27. class: '3rd',
  28. grades: {
  29. math: 10,
  30. physics: 15,
  31. programming: 12,
  32. english: 19
  33. }
  34. },
  35.  
  36. {
  37. name: 'Ahmed',
  38. class: '3rd',
  39. grades: {
  40. math: 20,
  41. physics: 20,
  42. programming: 20,
  43. english: 20
  44. }
  45. },
  46.  
  47. {
  48. name: 'Ali',
  49. class: '3rd',
  50. grades: {
  51. math: 20,
  52. physics: 25,
  53. programming: 19,
  54. english: 22
  55. }
  56. },
  57.  
  58. {
  59. name: 'Elgoker',
  60. class: '3rd',
  61. grades: {
  62. math: 23,
  63. physics: 25,
  64. programming: 19,
  65. english: 22
  66. }
  67. }
  68. ]
  69.  
  70. console.log(getLeaderBoard(students));
  71. console.log(students);
  72.  
Success #stdin #stdout 0.02s 16700KB
stdin
Standard input is empty
stdout
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]