Ranking methods: Difference between revisions
Content added Content deleted
m (→Functional ES5) |
|||
Line 801: | Line 801: | ||
ns = [44, 42, 42, 41, 41, 41, 39], |
ns = [44, 42, 42, 41, 41, 41, 39], |
||
sorted = xs.map(function ( |
sorted = xs.map(function (a, b) { |
||
return { name: |
return { name: a, score: ns[b] }; |
||
}).sort(function (a, b) { |
}).sort(function (a, b) { |
||
var |
var c = b.score - a.score; |
||
⚫ | |||
⚫ | |||
⚫ | |||
a.name < b.name ? -1 : ( |
|||
⚫ | |||
) |
|||
) |
|||
}), |
}), |
||
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([ |
return a.concat([ |
||
x. |
[x.name, x.score, |
||
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional |
|||
]]); |
|||
⚫ | |||
⚫ | |||
}, [])), |
}, [])), |
||