highest-averages
Version:
Zero-dependency and extensible set of highest averages methods for allocating seats in a parliament. ### Install ```shell npm i highest-averages ``` ### Pure Example - Define the candidates with their vote ```typescript const a = new Candidate('A', 200) c
21 lines (20 loc) • 659 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("./map_extensions");
Array.prototype.groupBy = function groupBy(selector) {
return this.reduce((map, value) => {
return map.set(selector(value), map.getOrElse(selector(value), []).concat(value));
}, (new Map));
};
Array.prototype.sum = function sum() {
return this.reduce((x, y) => x + y, 0);
};
Array.prototype.sumOf = function sumOf(selector) {
return this.map(selector).sum();
};
Array.prototype.flatten = function flatten() {
return this.reduce((x, y) => x.concat(y), []);
};
Array.prototype.clear = function clear() {
this.splice(0);
};