# round-discrete-distibution

> Round discrete distributions over diferent number of events

Latest version **1.1.0** (published 2022-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install round-discrete-distibution
pnpm add round-discrete-distibution
yarn add round-discrete-distibution
bun add round-discrete-distibution
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-01-21 |
| First published | 2022-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jbarog |
| Maintainers | jbarog |
| Keywords | round, stats, integer, probability, percentage |

## Links

- npm: https://www.npmjs.com/package/round-discrete-distibution
- Repository: https://github.com/jbarog/round-discrete-distibution
- Homepage: https://github.com/jbarog/round-discrete-distibution#readme
- Issues: https://github.com/jbarog/round-discrete-distibution/issues
- npm.io page: https://npm.io/package/round-discrete-distibution

## Dependencies (2)

- [sum-any-array](https://npm.io/package/sum-any-array.md) ^1.0.1
- [arrow-identity](https://npm.io/package/arrow-identity.md) ^1.0.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-01-21
- 1.0.0 — 2022-01-19

## README

# round-discrete-distibution
Round discrete distributions over different number of events

## Why?
I have 10 people grouped by ocupation:

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 1  | 4  | 3  | 2  |

and I want to keep same distribution over 15 people.

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 1.5  | 6  | 4.5  | 3  |

But it is disgusting 😵 have one and a half 👨‍⚕️

Lets round values!

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 2  | 6  | 5  | 3  |

No splited persons. 🎉 But now I have 16 people 😔.

**roundDiscreteDistribution** will return what I need:

*Integerdistribution*

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 2  | 6  | 4  | 3  |

but also:

*decimalDistribution*

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 1.5  | 6  | 4.5  | 3  |

*normalDistribution*

| 👨‍⚕️ | 👩‍🏫 | 👨‍🍳 | 👩‍🔧 |
|----|----|----|----|
| 0.14  | 0.4  | 0.26  | 0.2  |

##### Feature extra!!

And it accept number arrays
`[1, 4, 2, 3]`
and object arrays
```json
    [
      {
        "WHATEVER1": "👨‍⚕️",
		....
    	"WHATEVER2": 1
      },
      ...
    ]
```
## Install

`npm install --save round-discrete-distibution`

## Usage

```javascript
import { roundDiscreteDistibution } from 'round-discrete-distibution';

const initialDistribution = [1, 4, 3, 2];
const finalDistributionSize = 15;

const newDistribution = roundDiscreteDistibution(initialDistribution, finalDistributionSize);

console.log(newDistribution);
/*
{
    "decimalDistribution": [1.5, 6, 4.5, 3],
    "integerDistribution": [2, 6, 4, 3],
    "normalDistribution": [0.14, 0.4, 0.26, 0.2],
    "finalDistributionSize": 15,
}
*/
```
Or using object array:
```javascript
import { roundDiscreteDistibution } from 'round-discrete-distibution';

const initialDistribution =    [
      {
        "name": "👨‍⚕️",
        "value": 1
      },
      {
        "name": "👩‍🏫",
        "value": 4
      },
	  {
        "name": "👨‍🍳",
        "value": 3
      },
      {
        "name": "👩‍🔧",
        "value": 2
      },
    ];
const finalDistributionSize = 15;

const getValue = (item) => item.value;

const newDistribution = roundDiscreteDistibution(initialDistribution, finalDistributionSize, getValue);

console.log(newDistribution);
/*
{
    "decimalDistribution": [1.5, 6, 4.5, 3],
    "integerDistribution": [2, 6, 4, 3],
    "normalDistribution": [0.14, 0.4, 0.26, 0.2],
    "finalDistributionSize": 15,
}
*/
```
## License
MIT

---
_Source: https://npm.io/package/round-discrete-distibution · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
