Ranking methods: Difference between revisions

Content added Content deleted
Line 801: Line 801:
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 (a, b) {
return { name: x, score: ns[i] };
return { name: a, score: ns[b] };
}).sort(function (a, b) {
}).sort(function (a, b) {
var d = b.score - a.score;
var c = b.score - a.score;
return c ? c : a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
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; }),
scores = sorted.map(function (x) { return x.score; }),
scores = sorted.map(function (x) { return x.score; }),
Line 823: Line 818:


// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE

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

modified = function (score) {
modified = function (score) {
return reversed.length - reversed.indexOf(score);
return reversed.length - reversed.indexOf(score);
},
},

dense = function (score) {
dense = function (score) {
return unique.indexOf(score) + 1;
return unique.indexOf(score) + 1;
},
},

fractional = function (score) {
fractional = function (score) {
return (
return (
Line 847: Line 842:
name: names[index],
name: names[index],
score: score,
score: score,

Standard: standard(score),
Standard: standard(score),
Modified: modified(score),
Modified: modified(score),
Line 859: Line 854:
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
].concat(scores.map(rankings).reduce(function (a, x) {
].concat(scores.map(rankings).reduce(function (a, x) {
return a.concat([[x.name, x.score,
return a.concat([
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional
[x.name, x.score,
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional
]]);
]
]);
}, [])),
}, [])),