Ranking methods: Difference between revisions

Content added Content deleted
Line 797: Line 797:


<lang JavaScript>(function () {
<lang JavaScript>(function () {

var xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
var xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
ns = [44, 42, 42, 41, 41, 41, 39],
ns = [44, 42, 42, 41, 41, 41, 39],

sorted = xs.map(function (x, i) {
sorted = xs.map(function (x, i) {
return { name: x, score: ns[i] };
return { name: x, score: ns[i] };
Line 807: Line 807:
return c ? c : a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
return c ? c : 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; }),
scores = sorted.map(function (x) { return x.score; }),
scores = sorted.map(function (x) { return x.score; }),

reversed = scores.slice(0).reverse(),
reversed = scores.slice(0).reverse(),
unique = scores.filter(function (x, i) {
unique = scores.filter(function (x, i) {
return scores.indexOf(x) === i;
return scores.indexOf(x) === i;
});
});


// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
var rankings = function (score, index) {
return {
name: names[index],
score: score,


Ordinal: index + 1,
var standard = function (score) {
return scores.indexOf(score) + 1;
},


modified = function (score) {
Standard: function (n) {
return reversed.length - reversed.indexOf(score);
return scores.indexOf(n) + 1;
},
}(score),


dense = function (score) {
Modified: function (n) {
return unique.indexOf(score) + 1;
return reversed.length - reversed.indexOf(n);
},
}(score),


fractional = function (score) {
Dense: function (n) {
return (
return unique.indexOf(n) + 1;
(scores.indexOf(score) + 1) +
}(score),
(reversed.length - reversed.indexOf(score))
) / 2;
},


rankings = function (score, index) {
Fractional: function (n) {
return {
return (
name: names[index],
(scores.indexOf(n) + 1) +
score: score,
(reversed.length - reversed.indexOf(n))
) / 2;

Standard: standard(score),
}(score)
Modified: modified(score),
Dense: dense(score),
Ordinal: index + 1,
Fractional: fractional(score)
};
};
},
},

tbl = [
tbl = [
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
Line 860: Line 855:
]);
]);
}, [])),
}, [])),

//[[a]] -> bool -> s -> s
//[[a]] -> bool -> s -> s
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
Line 867: Line 862:
) + lstRows.map(function (lstRow, iRow) {
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');

return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
return typeof v === 'undefined' ? ' ' : v;
Line 873: Line 868:
}).join('') + '\n|}';
}).join('') + '\n|}';
};
};

return wikiTable(tbl, true, 'text-align:center');
return wikiTable(tbl, true, 'text-align:center');

})();</lang>
})();</lang>