Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hustcc/evenly
:sweat_drops: How to divide the gold evenly? No surplus. 怎么均匀并且无遗漏的分配黄金?
https://github.com/hustcc/evenly
allocate average divide evenly gold robbers
Last synced: about 2 months ago
JSON representation
:sweat_drops: How to divide the gold evenly? No surplus. 怎么均匀并且无遗漏的分配黄金?
- Host: GitHub
- URL: https://github.com/hustcc/evenly
- Owner: hustcc
- License: mit
- Created: 2017-02-27T01:56:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T02:53:47.000Z (almost 8 years ago)
- Last Synced: 2024-10-17T16:04:17.609Z (2 months ago)
- Topics: allocate, average, divide, evenly, gold, robbers
- Language: JavaScript
- Homepage: http://git.hust.cc/evenly/
- Size: 5.86 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# evenly
> **evenly** is a simple javascript library to solve problem which is similar to **how to divide the gold evenly?**
**Q**: How **3 robbers** to divide **100 gold**?
**A**: 100 / 3 can not solve it. But evenly can, **`evenly(100, 3)`** can get `[33.34, 33.33, 33.33]`. Done ^_^.
[![Build Status](https://travis-ci.org/hustcc/evenly.svg?branch=master)](https://travis-ci.org/hustcc/evenly) [![npm](https://img.shields.io/npm/v/evenly.svg?style=flat-square)](https://www.npmjs.com/package/evenly) [![npm](https://img.shields.io/npm/dt/evenly.svg?style=flat-square)](https://www.npmjs.com/package/evenly) [![npm](https://img.shields.io/npm/l/evenly.svg?style=flat-square)](https://www.npmjs.com/package/evenly)
# 1. Install
> **npm install evenly**
Then import it.
```js
var evenly = require('evenly');
//or
import evenly from 'evenly';
```Then use **evenly(gold, robber, fixed=2)** API.
```js
// 3 robber divide 100 golds, with 2 decimal.
evenly(100, 3, 1); // will return [33.4, 33.3, 33.3];evenly(100, 6); // will return [16.67, 16.67, 16.67, 16.67, 16.66, 16.66];
```# 2. API
The unique API is: **evenly(gold, robber, fixed=2)**.
- **gold** (Number): the number of gold.
- **robber** (Number): the number of robber who will divide the gold.
- **fixed** (Number): the decimal length, default is `2`.The api return the array which shows how to divide the gold evenly.
# 3. Build & Test
> npm install
> npm run build
> npm test
# 4. LICENSE
MIT @[hustcc](https://github.com/hustcc)