array-math
modularity
Sorry, I built this before I learned the truth about modularity. See the following links for enlightenment. ;-)
- http://substack.net/finding_modules
- http://substack.net/how_I_write_modules
- http://substack.net/many_things
api
var aMath =
aMath.factors(n)
If you only want this function, try primefactors.
n
must be a positive integer
aMath // -> [2]aMath // -> [2, 2, 2, 2, 2, 3]aMath // -> [2, 2, 5, 5]
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 insideopts
. Iftrue
, it will make the resulting array not includen
. Defaults tofalse
.
aMath // -> [2]aMath // -> [1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 96]aMath // -> [1, 2, 4, 5, 10, 20, 25, 50, 100]aMath // -> [1, 2, 4, 5, 10, 20, 25, 50]
aMath.isPrime(n)
If you only want this function, try isprime.
n
must be a positive integer
aMath // -> trueaMath // -> trueaMath // -> falseaMath // -> trueaMath // -> falseaMath // -> trueaMath // -> falseaMath // -> trueaMath // -> false
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 to0
. If there are 2 or 3 arguments, this is assumed to be the first.stop
is the ending number of the range. Defaults to0
. If there is 1 argument, this is assumed to be it.step
is the step between each number. Defaults to1
. This is may not be0
, and is set to1
if it is.
aMath // -> []aMath // -> []aMath // -> [0]aMath // -> [0, 1]aMath // -> []aMath // -> [2]aMath // -> [0, 1, 2]aMath // -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]aMath // -> [2, 3, 4, 5, 6, 7, 8, 9]aMath // -> [5, 6, 7, 8, 9]
aMath.multiply(a)
If you only want this function, it might be best to just write it yourself:
arr
a
must be an array of numbers (integers, floats, negative, whatever).
aMath // -> 19200aMath // -> 2040aMath // -> 790.4aMath // -> 16.64
aMath.sum(a)
If you only want this function, it might be best to just write it yourself:
arr
a
must be an array of numbers (integers, floats, negative, whatever).
aMath // -> 198aMath // -> 6aMath // -> 73.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 // -> 1aMath // -> 1aMath // -> 1aMath // -> 2 (2x1)aMath // -> 6 (3x2x1)aMath // -> 120 (5x4x3x2x1)aMath // -> 120 (5x4x3x2x1)aMath // -> 120 (5x4x3x2x1)aMath // -> 120 (5x4x3x2)aMath // -> 60 (5x4x3)aMath // -> 20 (5x4)aMath // -> 3628800 (10x9x8x7x6x5x4x3x2x1)aMath // -> 1814400 (10x9x8x7x6x5x4x3)aMath // -> 151200 (10x9x8x7x6x5)
install
Install with NPM
npm install array-math