Skip to content

Commit

Permalink
fix: use lodash-es
Browse files Browse the repository at this point in the history
lzear committed Jan 18, 2021
1 parent f4e03f8 commit b03e237
Showing 20 changed files with 167 additions and 141 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -82,11 +82,11 @@ The winner is the most-approved candidate.
**Borda count**: For each voter, every candidate is given a number of points
which equals the number of candidates ranked lower in the voter's preference.

**Nanson method**: Iterative Borda count in which, each round, candidates scoring
the average score or less are eliminated.
**Nanson method**: Iterative Borda count in which, each round, candidates
scoring the average score or less are eliminated.

**Baldwin method**: Iterative Borda count in which, each round, candidates scoring
the lowest score are eliminated.
**Baldwin method**: Iterative Borda count in which, each round, candidates
scoring the lowest score are eliminated.

**Instant-runoff**: Considering only the top choice of each voter, the candidate
with the fewest votes is eliminated. The election repeats until there is a
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@ module.exports = {
transform: {
'.(ts|tsx)': 'ts-jest',
},
moduleNameMapper: {
'^lodash-es$': 'lodash',
},
testEnvironment: 'node',
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js'],
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -53,32 +53,32 @@
"@commitlint/cli": "^11.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-node-resolve": "^11.1.0",
"@types/jest": "^26.0.20",
"@types/lodash-es": "^4.17.4",
"@types/node": "^14.14.20",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"commitizen": "^4.2.2",
"@types/node": "^14.14.21",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"commitizen": "^4.2.3",
"dotenv": "^8.2.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^4.3.7",
"husky": "^4.3.8",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.36.1",
"rollup": "^2.36.2",
"rollup-plugin-sizes": "^1.0.3",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.29.0",
"semantic-release": "^17.3.2",
"semantic-release": "^17.3.3",
"shelljs": "^0.8.4",
"travis-deploy-once": "^5.0.11",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typedoc": "^0.20.14",
"typedoc": "^0.20.16",
"typescript": "^4.1.3"
},
"dependencies": {
2 changes: 1 addition & 1 deletion src/methods/baldwin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import difference from 'lodash-es/difference'
import { difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
2 changes: 1 addition & 1 deletion src/methods/coombs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import difference from 'lodash-es/difference'
import { difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
3 changes: 1 addition & 2 deletions src/methods/copeland/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-plusplus */
import range from 'lodash-es/range'
import zipObject from 'lodash-es/zipObject'
import { range, zipObject } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
3 changes: 1 addition & 2 deletions src/methods/kemeny/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import zipObject from 'lodash-es/zipObject'
import range from 'lodash-es/range'
import { range, zipObject } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
2 changes: 1 addition & 1 deletion src/methods/maximal-lotteries/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zipObject from 'lodash-es/zipObject'
import { zipObject } from 'lodash-es'
import { solve } from '../../simplex'
import {
SystemUsingMatrix,
3 changes: 1 addition & 2 deletions src/methods/nanson/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sum from 'lodash-es/sum'
import difference from 'lodash-es/difference'
import { sum, difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
5 changes: 1 addition & 4 deletions src/methods/ranked-pairs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import groupBy from 'lodash-es/groupBy'
import range from 'lodash-es/range'
import uniq from 'lodash-es/uniq'
import zipObject from 'lodash-es/zipObject'
import { groupBy, range, uniq, zipObject } from 'lodash-es'
import {
Matrix,
ScoreObject,
2 changes: 1 addition & 1 deletion src/methods/schulze/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-plusplus */
import range from 'lodash-es/range'
import { range } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
2 changes: 1 addition & 1 deletion src/test/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import range from 'lodash-es/range'
import { range } from 'lodash-es'

export const product = (a: number[][], b: number[][]): number[][] => {
const dimA = [a.length, a[0].length]
5 changes: 1 addition & 4 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import fill from 'lodash-es/fill'
import random from 'lodash-es/random'
import range from 'lodash-es/range'
import shuffle from 'lodash-es/shuffle'
import { fill, random, range, shuffle } from 'lodash-es'
import { Ballot } from '../types'
import { toWeightedBallots } from '../utils'

2 changes: 1 addition & 1 deletion src/utils/condorcet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import difference from 'lodash-es/difference'
import { difference } from 'lodash-es'
import { Matrix } from '../types'

export const findCondorcet = ({ candidates, array }: Matrix): Matrix => {
4 changes: 1 addition & 3 deletions src/utils/makeMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import difference from 'lodash-es/difference'
import range from 'lodash-es/range'
import times from 'lodash-es/times'
import { difference, range, times } from 'lodash-es'
import { Matrix, Ballot } from '../types'

export const matrixFromBallots = (
14 changes: 8 additions & 6 deletions src/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import difference from 'lodash-es/difference'
import every from 'lodash-es/every'
import flatten from 'lodash-es/flatten'
import intersection from 'lodash-es/intersection'
import isEqual from 'lodash-es/isEqual'
import uniq from 'lodash-es/uniq'
import {
every,
difference,
flatten,
intersection,
uniq,
isEqual,
} from 'lodash-es'

import { Ballot } from '../types'

4 changes: 1 addition & 3 deletions src/utils/scores.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import groupBy from 'lodash-es/groupBy'
import sortBy from 'lodash-es/sortBy'
import toPairs from 'lodash-es/toPairs'
import { groupBy, sortBy, toPairs } from 'lodash-es'

export const scoresToRanking = (scores: {
[candidate: string]: number
2 changes: 1 addition & 1 deletion src/utils/scoresZero.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zipObject from 'lodash-es/zipObject'
import { zipObject } from 'lodash-es'
import { ScoreObject } from '../types'

export const scoresZero = (candidates: string[]): ScoreObject =>
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"moduleResolution": "node",
"target": "esnext",
"target": "es5",
"module": "es2015",
"lib": ["es7", "es2015", "es2016", "es2017", "es2019", "esnext", "dom"],
"strict": true,
218 changes: 126 additions & 92 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit b03e237

Please sign in to comment.