Ranking methods: Difference between revisions

Content added Content deleted
Line 791: Line 791:


===Functional ES5===
===Functional ES5===

The task formulation doesn't seem to directly explain or determine the order of listing for players whose score is the same.

( This version chooses to use a secondary (alphabetic sort) after the numeric sort by score. This does, of course, affect the ordinal placements for some players)


<lang JavaScript>(function () {
<lang JavaScript>(function () {
Line 799: Line 803:
sorted = xs.map(function (x, i) {
sorted = xs.map(function (x, i) {
return { name: x, score: ns[i] };
return { name: x, score: ns[i] };
}).sort(function (a, b) { return b.score - a.score; }),
}).sort(function (a, b) {
var d = b.score - a.score;
return d ? d : (
a.name < b.name ? -1 : (
a.name > b.name ? 1 : 0
)
)
}),
names = sorted.map(function (x) { return x.name; }),
names = sorted.map(function (x) { return x.name; }),
Line 877: Line 889:
| Solomon || 44 || 1 || 1 || 1 || 1 || 1
| Solomon || 44 || 1 || 1 || 1 || 1 || 1
|-
|-
| Jason || 42 || 2 || 3 || 2 || 2 || 2.5
| Errol || 42 || 2 || 3 || 2 || 2 || 2.5
|-
|-
| Errol || 42 || 2 || 3 || 2 || 3 || 2.5
| Jason || 42 || 2 || 3 || 2 || 3 || 2.5
|-
|-
| Garry || 41 || 4 || 6 || 3 || 4 || 5
| Barry || 41 || 4 || 6 || 3 || 4 || 5
|-
|-
| Bernard || 41 || 4 || 6 || 3 || 5 || 5
| Bernard || 41 || 4 || 6 || 3 || 5 || 5
|-
|-
| Barry || 41 || 4 || 6 || 3 || 6 || 5
| Garry || 41 || 4 || 6 || 3 || 6 || 5
|-
|-
| Stephen || 39 || 7 || 7 || 4 || 7 || 7
| Stephen || 39 || 7 || 7 || 4 || 7 || 7