Or alternatively:
(() => {
'use strict';
const main = () =>
scores(
Application('Keyboard Maestro Engine')
.getvariable('csvList')
);
// scores :: String -> String
const scores = strLines => {
const dctScores = strLines
.split('\n')
.reduce(
(a, x) => {
const k = x.split(',')[0];
return Object.assign(a, {
[k]: (a[k] || 0) + 1
});
}, {}
);
return Object.keys(dctScores)
.map(k => [k, dctScores[k]])
.sort(flip(comparing(x => x[1])))
.map(([k, n]) => k + '\t' + n)
.join('\n')
};
// comparing :: (a -> b) -> (a -> a -> Ordering)
const comparing = f =>
(x, y) => {
const
a = f(x),
b = f(y);
return a < b ? -1 : (a > b ? 1 : 0);
};
// flip :: (a -> b -> c) -> b -> a -> c
const flip = f => (a, b) => f(...[b, a]);
// MAIN ---
return main();
})();