Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
76
Task/Ranking-methods/JavaScript/ranking-methods-1.js
Normal file
76
Task/Ranking-methods/JavaScript/ranking-methods-1.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
(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] };
|
||||
}).sort(function (a, b) {
|
||||
var c = b.score - a.score;
|
||||
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 rankings = function (score, index) {
|
||||
return {
|
||||
name: names[index],
|
||||
score: score,
|
||||
|
||||
Ordinal: index + 1,
|
||||
|
||||
Standard: function (n) {
|
||||
return scores.indexOf(n) + 1;
|
||||
}(score),
|
||||
|
||||
Modified: function (n) {
|
||||
return reversed.length - reversed.indexOf(n);
|
||||
}(score),
|
||||
|
||||
Dense: function (n) {
|
||||
return unique.indexOf(n) + 1;
|
||||
}(score),
|
||||
|
||||
Fractional: function (n) {
|
||||
return (
|
||||
(scores.indexOf(n) + 1) +
|
||||
(reversed.length - reversed.indexOf(n))
|
||||
) / 2;
|
||||
}(score)
|
||||
};
|
||||
},
|
||||
|
||||
tbl = [
|
||||
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
|
||||
].concat(scores.map(rankings).reduce(function (a, x) {
|
||||
return a.concat([
|
||||
[x.name, x.score,
|
||||
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional
|
||||
]
|
||||
]);
|
||||
}, [])),
|
||||
|
||||
//[[a]] -> bool -> s -> s
|
||||
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
|
||||
return '{| class="wikitable" ' + (
|
||||
strStyle ? 'style="' + strStyle + '"' : ''
|
||||
) + lstRows.map(function (lstRow, iRow) {
|
||||
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
|
||||
|
||||
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
|
||||
return typeof v === 'undefined' ? ' ' : v;
|
||||
}).join(' ' + strDelim + strDelim + ' ');
|
||||
}).join('') + '\n|}';
|
||||
};
|
||||
|
||||
return wikiTable(tbl, true, 'text-align:center');
|
||||
|
||||
})();
|
||||
59
Task/Ranking-methods/JavaScript/ranking-methods-2.js
Normal file
59
Task/Ranking-methods/JavaScript/ranking-methods-2.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
((() => {
|
||||
const xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
|
||||
ns = [44, 42, 42, 41, 41, 41, 39];
|
||||
|
||||
const sorted = xs.map((x, i) => ({
|
||||
name: x,
|
||||
score: ns[i]
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
const c = b.score - a.score;
|
||||
return c ? c : a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
||||
});
|
||||
|
||||
const names = sorted.map(x => x.name),
|
||||
scores = sorted.map(x => x.score),
|
||||
reversed = scores.slice(0)
|
||||
.reverse(),
|
||||
unique = scores.filter((x, i) => scores.indexOf(x) === i);
|
||||
|
||||
// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
|
||||
|
||||
// rankings :: Int -> Int -> Dictonary
|
||||
const rankings = (score, index) => ({
|
||||
name: names[index],
|
||||
score,
|
||||
Ordinal: index + 1,
|
||||
Standard: scores.indexOf(score) + 1,
|
||||
Modified: reversed.length - reversed.indexOf(score),
|
||||
Dense: unique.indexOf(score) + 1,
|
||||
|
||||
Fractional: (n => (
|
||||
(scores.indexOf(n) + 1) +
|
||||
(reversed.length - reversed.indexOf(n))
|
||||
) / 2)(score)
|
||||
});
|
||||
|
||||
// tbl :: [[[a]]]
|
||||
const tbl = [
|
||||
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
|
||||
].concat(scores.map(rankings)
|
||||
.reduce((a, x) => a.concat([
|
||||
[x.name, x.score,
|
||||
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional
|
||||
]
|
||||
]), []));
|
||||
|
||||
// wikiTable :: [[[a]]] -> Bool -> String -> String
|
||||
const wikiTable = (lstRows, blnHeaderRow, strStyle) =>
|
||||
`{| class="wikitable" ${strStyle ? 'style="' + strStyle + '"' : ''}
|
||||
${lstRows.map((lstRow, iRow) => {
|
||||
const strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
|
||||
|
||||
return '\n|-\n' + strDelim + ' ' + lstRow
|
||||
.map(v => typeof v === 'undefined' ? ' ' : v)
|
||||
.join(' ' + strDelim + strDelim + ' ');
|
||||
}).join('')}\n|}`;
|
||||
|
||||
return wikiTable(tbl, true, 'text-align:center');
|
||||
}))();
|
||||
Loading…
Add table
Add a link
Reference in a new issue