# sum-any-array

> Sum plain arrays and object arrays

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

## Install

```sh
npm install sum-any-array
pnpm add sum-any-array
yarn add sum-any-array
bun add sum-any-array
```

## 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.0.1 |
| Published | 2022-01-21 |
| First published | 2022-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jbarog |
| Maintainers | jbarog |
| Keywords | reduce, integer, object, parse |

## Links

- npm: https://www.npmjs.com/package/sum-any-array
- Repository: https://github.com/jbarog/sum-any-array
- Homepage: https://github.com/jbarog/sum-any-array#readme
- Issues: https://github.com/jbarog/sum-any-array/issues
- npm.io page: https://npm.io/package/sum-any-array

## Dependencies (1)

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

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

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

## README

# round-discrete-distibution
Sum plain arrays and object arrays cause it can accept a second optional parameter that parse array value.
So it accept a parser method so can accept number arrays
`[1, 4, 2, 3]`
and other type of content like object arrays
```json
    [
      {
		....
    	"WHATEVER2": 1
      },
      ...
    ]
```

## Install

`npm install --save sum-any-array`

## Usage
### sumArray
This method sums an array that could be an array of objects if parse function is provided.
```javascript
const sumArray = require('sum-any-array');

const numberArray = [1, 4, 2, 3];

const sum = sumArray(numberArray);

console.log(sum);
/*
10
*/
```
Using object array:
```javascript
const sumArray = require('sum-any-array');

const objArray = [
      {
        "name": "👨‍⚕️",
        "value": 1
      },
      {
        "name": "👩‍🏫",
        "value": 4
      },
	  {
        "name": "👨‍🍳",
        "value": 3
      },
      {
        "name": "👩‍🔧",
        "value": 2
      },
    ];
const getValue = (item) => item.value;

const sum = sumArray(objArray, getValue);

console.log(sum);
/*
10
*/
```

Using string array:
```javascript
const sumArray = require('sum-any-array');

const strArray = ['a','b','ee'],;
const strLength = (str) => str.length;

const sum = sumArray(strArray, getValue);

console.log(sum);
/*
4
*/
```
## License
MIT

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