ez-math.js
v1.1.7
Published
A simple package to make doing mathematical operations very easy!
Downloads
2
Readme
easy-math.js
A javascript package that makes doing math operations very easy and simple
How to Use:
npm install easy-math.js
both: [n1, n2, n3] and 'n1, n2, n3' (array and string) are supported as parameters.
Global Rules: The operation is performed upon the first parameter and 0, or 1(multiplication and other operations like it, because if it was 0, it would always return 0(0 x anything = 0)), and then between the answer of that and the next parameter, effectively like using parenthesis, so for certain operations, like power, order matters tremendously.
Example
const math = require('ez-math.js'); //importing the package
console.log(math.add('1, 2, 3, 4')); //returns 10
console.log(math.add([1, 2, 3 , 4])); //also returns 10
console.log(math.subtr([1, 2, 3, 4])) //subtracts all parameters from 0, this returns -10
console.log(math.div([1, 2, 3])) //divides the first 2 parameters(1 and 2), and gets 0.5; divides that by next param and returns what it has when there are no more params to loop through. this returns 0.1666...
console.log(math.multi('1, 2, 3, 4, 5')) //multiplies all parameters together, this returns 120.
console.log(math.pow('10, 2, 4')) //treated as parentheses; raises 1st param ^ 2nd param(10^2), and then raises the answer to the next param and repeats until there are no more parameters to loop through.
Methods:
add - adds all of the numbers specified
Parameters - array(required)
type: string or array
example: math.add([1, 2, 3, 4]) OR math.add('1, 2, 3 ,4') 1 STRING, the commas are inside the string, not representing new strings.
subtr - subtracts all of the numbers specified in the same order
Parameters - array(required)
type: string or array
example: math.subtr([1, 2, 3, 4]) - returns -8 (executes [(1-2)-3]-4)
multi - multiplies all numbers specified
Parameters - array(required)
type: string or array
example: math.multi([1, 2, 3, 4]) returns 24 (executes [(1 * 2) * 3] * 4)
div - divides all numbers specified in the same order
Parameters - array(required)
type: string or array
example: math.div([1, 2, 3, 4]) - returns 0.041666666666666664 (executes [(1 / 2) / 3] / 4)
pow - raises array[0] to array[1] and raises that to the next parameter. - continues until there is nothing else to loop through(see example for better understanding)
Parameters - array(required)
type: string or array
example: math.pow([5, 2, 3]) - returns 15625 (executes [5 ^ 2] ^ 3)(the same as: math.pow([5, math.multi([2, 3])])), which multiplies 2 and 3, getting 6, and raises 5 to that(5^6)
avg - takes the average value of numbers in an array.
Parameters - array(required)
type: string or array
example math.avg('1, 2, 3, 4, 5') - returns 3, because the average value of the numbers is 3.