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