Ranking methods: Difference between revisions
→Functional ES5
m (→Functional ES5) |
|||
Line 797:
<lang JavaScript>(function () {
var xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
ns = [44, 42, 42, 41, 41, 41, 39],
sorted = xs.map(function (x, i) {
return { name: x, score: ns[i] };
Line 807:
return c ? c : a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}),
names = sorted.map(function (x) { return x.name; }),
scores = sorted.map(function (x) { return x.score; }),
reversed = scores.slice(0).reverse(),
unique = scores.filter(function (x, i) {
return scores.indexOf(x) === i;
});
// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
▲ var standard = function (score) {
}(score),
return
}(score),
return unique.indexOf(n) + 1;
▲ ) / 2;
return
) / 2;
▲ Modified: modified(score),
▲ Dense: dense(score),
▲ Ordinal: index + 1,
};
},
tbl = [
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
Line 860 ⟶ 855:
]);
}, [])),
//[[a]] -> bool -> s -> s
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
Line 867 ⟶ 862:
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
Line 873 ⟶ 868:
}).join('') + '\n|}';
};
return wikiTable(tbl, true, 'text-align:center');
})();</lang>
|