array-math
modularity
Sorry, I built this before I learned the truth about modularity. See the following links for enlightenment. ;-)
api
var aMath = require('array-math')
aMath.factors(n)
If you only want this function, try primefactors.
n
must be a positive integer
aMath.factors(2)
aMath.factors(96)
aMath.factors(100)
aMath.divisors(n[, opts])
If you only want this function, you could factor it out, and send me a PR with a link to your module! (Grab the test file while you're at it.)
n
must be a positive number.opts
is an object with the options. Defaults to {}
.
proper
can be inside opts
. If true
, it will make the resulting array not include n
. Defaults to false
.
aMath.divisors(2)
aMath.divisors(96)
aMath.divisors(100)
aMath.divisors(100, {proper:true})
aMath.isPrime(n)
If you only want this function, try isprime.
n
must be a positive integer
aMath.isPrime(2)
aMath.isPrime(3)
aMath.isPrime(4)
aMath.isPrime(7)
aMath.isPrime(96)
aMath.isPrime(97)
aMath.isPrime(100)
aMath.isPrime(113)
aMath.isPrime(117)
aMath.range([start,] stop [,step])
If you only want this function, try array-range. (Does not have stepping built in.)
start
is the starting number of the range. Defaults to 0
. If there are 2 or 3 arguments, this is assumed to be the first.stop
is the ending number of the range. Defaults to 0
. If there is 1 argument, this is assumed to be it.step
is the step between each number. Defaults to 1
. This is may not be 0
, and is set to 1
if it is.
aMath.range()
aMath.range(0)
aMath.range(1)
aMath.range(2)
aMath.range(2, 2)
aMath.range(2, 3)
aMath.range(3)
aMath.range(10)
aMath.range(2, 10)
aMath.range(5, 10)
aMath.multiply(a)
If you only want this function, it might be best to just write it yourself:
arr.reduce(function (prdct, fctr) { return prdct * fctr }, 1)
a
must be an array of numbers (integers, floats, negative, whatever).
aMath.multiply([2, 96, 100])
aMath.multiply([40, 3, 17])
aMath.multiply([4, 5, 2, 5.2, 3.8])
aMath.multiply([520, 0.2, 0.2, 0.8])
aMath.sum(a)
If you only want this function, it might be best to just write it yourself:
arr.reduce(function (sum, val) { return sum + val }, 0)
a
must be an array of numbers (integers, floats, negative, whatever).
aMath.sum([2, 96, 100])
aMath.sum([2, -96, 100])
aMath.sum([45, 20, 8.3])
aMath.factorial(h[, l])
If you only want this function, try factorial. (Does not have low number built in.)
h
must be a number. It is the high number. It defaults to 0.l
must be a number. It is the low number. It defaults to 0.
While multiplying, it will never multiply by 0.
aMath.factorial()
aMath.factorial(0)
aMath.factorial(1)
aMath.factorial(2)
aMath.factorial(3)
aMath.factorial(5)
aMath.factorial(5, 0)
aMath.factorial(5, 1)
aMath.factorial(5, 2)
aMath.factorial(5, 3)
aMath.factorial(5, 4)
aMath.factorial(10)
aMath.factorial(10, 3)
aMath.factorial(10, 5)
install
Install with NPM
npm install array-math
license
VOL