Ranking methods: Difference between revisions
Content added Content deleted
m (→Functional ES5) |
|||
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 |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return scores.indexOf(score) + 1; |
|||
}, |
|||
Standard: function (n) { |
|||
return scores.indexOf(n) + 1; |
|||
}, |
}(score), |
||
Modified: function (n) { |
|||
return |
return reversed.length - reversed.indexOf(n); |
||
}, |
}(score), |
||
Dense: function (n) { |
|||
return ( |
return unique.indexOf(n) + 1; |
||
}(score), |
|||
(reversed.length - reversed.indexOf(score)) |
|||
⚫ | |||
}, |
|||
Fractional: function (n) { |
|||
return |
return ( |
||
(scores.indexOf(n) + 1) + |
|||
(reversed.length - reversed.indexOf(n)) |
|||
) / 2; |
|||
}(score) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
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> |
||