math-array
v1.1.2
Published
Math utility to calculate with two arrays.
Downloads
347
Maintainers
Readme
math-array
Math utility to calculate with two arrays.
Install
$ npm install math-array
Usage
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. Iftrue
, the returned value will be cleaned, and every item which is not a number will be removed.
mul([1, 2], [1, undefined]) // [1, NaN]
mul([1, 2], [1, undefined], true) // [1, <1 empty item>]
License
MIT