npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

largest-remainder

v1.0.3

Published

The [largest remainder method](https://en.wikipedia.org/wiki/Largest_remainder_method) (also known as Hare–Niemeyer method, Hamilton method or as Vinton's method) is one way of [allocating seats proportionally](<https://en.wikipedia.org/wiki/Apportionment

Downloads

19

Readme

Largest Remainder

The largest remainder method (also known as Hare–Niemeyer method, Hamilton method or as Vinton's method) is one way of allocating seats proportionally for representative assemblies with voting systems.

Installation

yarn add largest-remainder

Usage

const largestRemainder = require('largest-remainder')

const votes = {
	Conservatives: 13636684,
	Labour: 12877918,
	SNP: 977568,
	'Liberal Democrats': 2371861,
	Green: 525665,
	Other: 746144
}
const seats = 650

let government = largestRemainder(votes, seats, 'hare')
console.table(government)

Results

┌─────────┬────────┬─────────────────────┬──────────┬──────────────────────┬────────────────────┬─────────────────────┬───────┬──────────────────────┬──────────────────────┐
│ (index) │  type  │        party        │  votes   │      percentage      │    distribution    │      remainder      │ seats │        error         │   percentageSeats    │
├─────────┼────────┼─────────────────────┼──────────┼──────────────────────┼────────────────────┼─────────────────────┼───────┼──────────────────────┼──────────────────────┤
│    0    │ 'hare' │   'Conservatives'   │ 13636684 │  0.437973859064024   │ 284.6830083916156  │ 0.6830083916155445  │  285  │ 0.31699160838439866  │ 0.43846153846153846  │
│    1    │ 'hare' │      'Labour'       │ 12877918 │ 0.41360432222159416  │ 268.8428094440362  │ 0.8428094440361633  │  269  │ 0.15719055596377984  │ 0.41384615384615386  │
│    2    │ 'hare' │ 'Liberal Democrats' │ 2371861  │ 0.07617783878642748  │ 49.51559521117786  │ 0.5155952111778532  │  49   │  0.5155952111778603  │ 0.07538461538461538  │
│    3    │ 'hare' │        'SNP'        │  977568  │ 0.031396872543024375 │ 20.407967152965842 │ 0.40796715296584196 │  20   │ 0.40796715296584196  │ 0.03076923076923077  │
│    4    │ 'hare' │       'Other'       │  746144  │ 0.02396415192267175  │ 15.576698749736638 │ 0.5766987497366376  │  16   │  0.4233012502633624  │ 0.024615384615384615 │
│    5    │ 'hare' │       'Green'       │  525665  │ 0.016882955462258285 │ 10.973921050467885 │ 0.9739210504678848  │  11   │ 0.026078949532115203 │ 0.016923076923076923 │
└─────────┴────────┴─────────────────────┴──────────┴──────────────────────┴────────────────────┴─────────────────────┴───────┴──────────────────────┴──────────────────────┘

Quotas

Available quotas are hare, droop, hagenbach-bischoff and imperiali. See Quotas

Not providing a quota, rounds the seats down before ordering by the largest remainder and incrementally increasing.

droop quota defaults to hare quota when quota <= seats

Results object

  • type the quota used
  • party the original key name
  • votes the original key value
  • percentage the overall percentage of votes received
  • distribution how the seats should be distributed
  • remainder the remainder used to order the results before addition of new seats
  • seats the seats allocated to the party
  • error how far off the distribution is the seats
  • percentageSeats what percentage the seats now represent

Credits

Written by Nic Mulvaney @ Normally

Inspired by https://github.com/juliuste/hare-niemeyer