Skip to content

Commit

Permalink
Merge pull request #43 from lzear/nanson
Browse files Browse the repository at this point in the history
fix: use lodash-es
  • Loading branch information
lzear authored Jan 18, 2021
2 parents deafa33 + b03e237 commit dee7822
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 154 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,36 @@
"@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": "^4.14.167",
"@types/node": "^14.14.20",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"commitizen": "^4.2.2",
"@types/lodash-es": "^4.17.4",
"@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.1",
"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.19.2",
"typedoc": "^0.20.16",
"typescript": "^4.1.3"
},
"dependencies": {
"lodash": "^4.17.20"
"lodash-es": "^4.17.20"
},
"bugs": {
"url": "https://github.com/lzear/votes/issues"
Expand Down
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/difference'
import { difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
Expand Down
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/difference'
import { difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
Expand Down
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/range'
import zipObject from 'lodash/zipObject'
import { range, zipObject } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
Expand Down
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/zipObject'
import range from 'lodash/range'
import { range, zipObject } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
Expand Down
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/zipObject'
import { zipObject } from 'lodash-es'
import { solve } from '../../simplex'
import {
SystemUsingMatrix,
Expand Down
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/sum'
import difference from 'lodash/difference'
import { sum, difference } from 'lodash-es'
import {
SystemUsingRankings,
ScoreObject,
Expand Down
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/groupBy'
import range from 'lodash/range'
import uniq from 'lodash/uniq'
import zipObject from 'lodash/zipObject'
import { groupBy, range, uniq, zipObject } from 'lodash-es'
import {
Matrix,
ScoreObject,
Expand Down
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/range'
import { range } from 'lodash-es'
import {
SystemUsingMatrix,
VotingSystem,
Expand Down
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/range'
import { range } from 'lodash-es'

export const product = (a: number[][], b: number[][]): number[][] => {
const dimA = [a.length, a[0].length]
Expand Down
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/fill'
import random from 'lodash/random'
import range from 'lodash/range'
import shuffle from 'lodash/shuffle'
import { fill, random, range, shuffle } from 'lodash-es'
import { Ballot } from '../types'
import { toWeightedBallots } from '../utils'

Expand Down
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/difference'
import { difference } from 'lodash-es'
import { Matrix } from '../types'

export const findCondorcet = ({ candidates, array }: Matrix): Matrix => {
Expand Down
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/difference'
import range from 'lodash/range'
import times from 'lodash/times'
import { difference, range, times } from 'lodash-es'
import { Matrix, Ballot } from '../types'

export const matrixFromBallots = (
Expand Down
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/difference'
import every from 'lodash/every'
import flatten from 'lodash/flatten'
import intersection from 'lodash/intersection'
import isEqual from 'lodash/isEqual'
import uniq from 'lodash/uniq'
import {
every,
difference,
flatten,
intersection,
uniq,
isEqual,
} from 'lodash-es'

import { Ballot } from '../types'

Expand Down
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/groupBy'
import sortBy from 'lodash/sortBy'
import toPairs from 'lodash/toPairs'
import { groupBy, sortBy, toPairs } from 'lodash-es'

export const scoresToRanking = (scores: {
[candidate: string]: number
Expand Down
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/zipObject'
import { zipObject } from 'lodash-es'
import { ScoreObject } from '../types'

export const scoresZero = (candidates: string[]): ScoreObject =>
Expand Down
Loading

0 comments on commit dee7822

Please sign in to comment.