Skip to content
WANCODE
BM

Sort Students by Score

15 minIntermediateJavaScript

Cikgu Rina wants a ranking table for her class quiz. The current code puts the lowest score on top, shuffles students with equal scores unpredictably, and quietly rearranges the original students array that other parts of the app rely on.

JavaScript
sortStudents(students).map((s) => s.name)
// ["Hafiz", "Farid", "Wei Ling", "Arjun", "Aisyah", "Mei"]
//   100      92       92         85       78        9
//   Farid and Wei Ling both have 92 → A–Z by name

Expected order for the sample data

Constraints

  • Each student is an object like { name: "Arjun", score: 85 }. Return the same objects, re-ordered.
  • Highest score first. Equal scores → alphabetical by name (A–Z).
  • Return a new array; the array passed in must keep its original order. An empty list returns [].

Fix sortStudents(list) so it returns a new array of student objects sorted by score (highest first), breaking ties by name A–Z, without changing the original array.

Checks

  • Highest score first
  • Equal scores are ordered A–Z
  • Returns a new array and leaves the original alone
  • The table shows the ranking
Preview

Console output from your code appears here.

Step 1 of 1