math-array
Version:
Math utility to calculate with two arrays.
68 lines (52 loc) • 1.98 kB
Markdown
[](https://travis-ci.org/kaelzhang/node-math-array)
[](https://codecov.io/gh/kaelzhang/node-math-array)
<!-- optional appveyor tst
[](https://ci.appveyor.com/project/kaelzhang/node-math-array)
-->
<!-- optional npm version
[](http://badge.fury.io/js/math-array)
-->
<!-- optional npm downloads
[](https://www.npmjs.org/package/math-array)
-->
<!-- optional dependency status
[](https://david-dm.org/kaelzhang/node-math-array)
-->
# math-array
Math utility to calculate with two arrays.
## Install
```sh
$ npm install math-array
```
## Usage
```js
import {
add,
sub,
mul,
div
} from 'math-array'
// Add 2 items
add([1, 2], [3, 4]) // [4, 6]
add([1, 2], 3) // [4, 5]
add(3, [1, 2]) // [4, 5]
add(1, 2) // Error, at least one array is required
// Sub 2 items
sub(1, [1, 2]) // Error, the first argument must be an array
sub([1, 2], 1) // [0, 1]
sub([1, 2], [1, 2]) // [0, 0]
// Multiply 2 items
mul([1, 2], [1, 2]) // [1, 4]
// Divide 2 items
div([1, 2], [0, 1]) // Error, divide by zero
```
## `<method>(a, b, ensureNumber)`
- **a** `Array.<Number>`
- **b** `Array.<Number>`
- **ensureNumber** `Boolean=false` `math-array` manipulate arrays by simply adding, multiplying items. If `true`, the returned value will be cleaned, and every item which is not a number will be removed.
```js
mul([1, 2], [1, undefined]) // [1, NaN]
mul([1, 2], [1, undefined], true) // [1, <1 empty item>]
```
## License
MIT