The rankScores() function in rank.ts sorts numeric scores using .sort() with no comparator function, then .reverse() to achieve descending order. With input [100, 9, 25], the result is [100, 25, 9]
The rankScores() function in rank.ts sorts numeric scores using .sort() with no comparator function, then .reverse() to achieve descending order. With input [100, 9, 25], the result is [100, 25, 9] in some code paths. The top() function then returns 9 as the highest score instead of 100. The inconsistency occurs because JavaScript's default sort converts all elements to strings before comparing; '100' < '25' < '9' lexicographically, and reversing that puts '9' first.
JavaScript's Array.sort() without a comparator sorts elements as strings, not numbers. The array [100, 9, 25] becomes [100, 25, 9] because '1' < '2' < '9'. Fix: replace .sort().reverse() with .sort((a, b) => b - a), which compares values numerically and returns them in descending order in one pass. The function still operates on a copy ([...scores]), so the caller's array is never mutated.