Ranking methods: Difference between revisions

(added AutoHotkey)
Line 786:
5,0 41 Barry
7,0 39 Stephen</pre>
 
 
=={{header|JavaScript}}==
 
===Functional ES5===
 
<lang JavaScript>(function () {
 
var xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
ns = [44, 42, 42, 41, 41, 41, 39],
 
reversed = ns.slice(0).reverse(),
unique = ns.filter(function (n, i) {
return ns.indexOf(n) === i;
}),
 
rankings = function (score, index, list) {
 
return {
name: xs[index],
score: score,
 
// RANKINGS AS FUNCTIONS OF SCORE, LIST, INDEX, REVERSED AND UNIQUE
 
Standard: list.indexOf(score) + 1,
 
Modified: reversed.length - reversed.indexOf(score),
 
Dense: unique.indexOf(score) + 1,
 
Ordinal: index + 1,
 
Fractional: (
(list.indexOf(score) + 1) +
(reversed.length - reversed.indexOf(score))
) / 2
};
},
 
tbl = [
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
].concat(
ns.map(rankings).reduce(
function (a, x) {
return a.concat([
[ x.name, x.score,
x.Standard, x.Modified, x.Dense,
x.Ordinal, x.Fractional
]
]);
}, []
)
),
 
//[[a]] -> bool -> s -> s
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
return '{| class="wikitable" ' + (
strStyle ? 'style="' + strStyle + '"' : ''
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
 
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
}).join(' ' + strDelim + strDelim + ' ');
}).join('') + '\n|}';
};
 
return wikiTable(tbl, true, 'text-align:center');
 
})();</lang>
 
{{out}}
 
{| class="wikitable" style="text-align:center"
|-
! Name !! Score !! Standard !! Modified !! Dense !! Ordinal !! Fractional
|-
| Solomon || 44 || 1 || 1 || 1 || 1 || 1
|-
| Jason || 42 || 2 || 3 || 2 || 2 || 2.5
|-
| Errol || 42 || 2 || 3 || 2 || 3 || 2.5
|-
| Garry || 41 || 4 || 6 || 3 || 4 || 5
|-
| Bernard || 41 || 4 || 6 || 3 || 5 || 5
|-
| Barry || 41 || 4 || 6 || 3 || 6 || 5
|-
| Stephen || 39 || 7 || 7 || 4 || 7 || 7
|}
 
=={{header|jq}}==
We assume the list of players and their scores has already been sorted,
9,659

edits