math
Functions
- compareNumbers(a, b, operator) ⇒
boolean
Check if
a
is comparative tob
with the given operator.- evaluate(equation) ⇒
number
Evaluate mathematical strings.
- isNumeric(val) ⇒
boolean
Check if the given value is a valid finite number.
- isSafeNumber(val) ⇒
boolean
Check if the given value is a "safe" number.
A "safe" number falls within the
Number.MAX_SAFE_INTEGER
andNumber.MIN_SAFE_INTEGER
values (Inclusive).- sumArray(numbers) ⇒
number
Take an array of numbers and add the values together.
- toFixed(num, [precision]) ⇒
number
Round a number to the given amount of digits after the decimal point, removing any trailing zeros after the decimal point.
boolean
compareNumbers(a, b, operator) ⇒ Check if a
is comparative to b
with the given operator.
Kind: global function
Returns: boolean
- true
if the comparison matches, false
otherwise
Param | Type | Description |
---|---|---|
a | number | The number to compare with b |
b | number | The number to compare with a |
operator | string | A valid comparative operator: =, <, >, <=, >=, !=, <> |
Example (Is `a` greater than `b`?)
const a = 4;
const b = 2;
compareNumber(a, b, '>'); // true
Example (Is `a` equal to `b`?)
const a = 4;
const b = 2;
compareNumber(a, b, '='); // false
number
evaluate(equation) ⇒ Evaluate mathematical strings.
Kind: global function
Returns: number
- The result of the equation
Param | Type | Description |
---|---|---|
equation | string | The mathematical equation to compute. |
Example
evaluate('5+6'); // 11
boolean
isNumeric(val) ⇒ Check if the given value is a valid finite number.
Kind: global function
Returns: boolean
- true
if it is a finite number, false
otherwise
Param | Type |
---|---|
val | * |
boolean
isSafeNumber(val) ⇒ Check if the given value is a "safe" number.
A "safe" number falls within the Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER
values (Inclusive).
Kind: global function
Returns: boolean
- true
if the value is a "safe" number, false
otherwise
Param | Type |
---|---|
val | * |
number
sumArray(numbers) ⇒ Take an array of numbers and add the values together.
Kind: global function
Returns: number
- The summed value
Param | Type |
---|---|
numbers | Array.<number> |
number
toFixed(num, [precision]) ⇒ Round a number to the given amount of digits after the decimal point, removing any trailing zeros after the decimal point.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
num | number | The number to round | |
[precision] | number | 0 | The number of digits after the decimal point |
Example
toFixed(1.236, 2); // 1.24
toFixed(30.1, 2); // 30.1
toFixed(4.0000000004, 3); // 4