Dev Helpers

JavaScript / Collections in practice

Resolve ranked ties

Dev Helpers · November 28, 2026

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.

Worked example

const scores = [10, 8, 8, 6];
console.log(scores.map((v) => 1 + scores.filter((s) => s > v).length));

Result

[ 1, 2, 2, 4 ]

Implementation notes

Stable ordering makes ties repeatable only if the input order is repeatable too. A persistent secondary key prevents a leaderboard from jumping after a refresh.

Try it yourself

Add three matching scores and decide which rank follows the tie.

Open the JavaScript example →

Editorial date November 28, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Get the last day of a month

Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.