Methods#
(static) average(…numbers) → {number}#
Calculates a average/mean of all givens numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| the numbers to average |
Examples | average(5,4,3,6,7,3,1,8); |
| average(1,2,-5,2.4,-6.5,0.5); |
| average(1,2,3,4,5,6,7,8,9); |
| average(-1,2,3,4,5,6,7,8,-9); |
| average(...[1,2,3,4,5,6]); |
(static) clamp(value, minopt, maxopt) → {number}#
If the value is greater than the maximum, returns the maximum. If the value is less than the minimum, returns the minimum. If not, return the passed value.
Parameters:Name | Type | Attributes | Default | Description |
---|
value | number | | | The value to check |
min | number | <optional>
| 0 | Minimum value |
max | number | <optional>
| 1 | Maximum value |
(static) degreesToRadians(d) → {number}#
Return the givens value in radians
Parameters:Name | Type | Description |
---|
d | number | the degrees value to convert in radians |
Returns:converted the given degrees in radian
- Type:
- number
(static) divideEvenly(minopt, maxopt, numberDivisionsopt) → {Array.<number>}#
Returns a array with the dived evenly between the two numbers
Parameters:Name | Type | Attributes | Default | Description |
---|
min | number | <optional>
| 0 | The minimum value to return. |
max | number | <optional>
| 10 | The maximum value to return. |
numberDivisions | number | <optional>
| 5 | The number of divisions to use. |
Returns:An array of evenly spaced numbers.
- Type:
- Array.<number>
Examples | divideEvenly(-45, 45, 3); |
(static) division(…numbers) → {number}#
Calculates a division of all givens numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| the numbers to division |
Examples | division(1,2,-5,2.4,-6.5,0.5); |
(static) factorial(number) → {number}#
The factorial of a non-negative number is computed as the product of all integers between 1 and the number itself
Parameters:Name | Type | Description |
---|
number | number | the number to factoring |
(static) getPositionWithAngleDistance(angle, distance, originopt) → {Point}#
Calculates de position (x,y) of a object based in the angle and distance
Parameters:Name | Type | Attributes | Description |
---|
angle | number | | the angle to evaluate |
distance | number | | the distance to evaluate |
origin | Object | <optional>
| origin position to analyze PropertiesName | Type | Attributes | Default | Description |
---|
x | number | <optional>
| 0 | x axis value | y | number | <optional>
| 0 | y axis value |
|
Returns:position {x:number,y:number} the x and y position
- Type:
- Point
Example | getPositionWithAngleDistance(10, 100); |
(static) invertedLerp(value, start, end) → {number}#
Determines where a value lies between two points.
Parameters:Name | Type | Description |
---|
value | number | The point within the range you want to calculate. |
start | number | The start of the range. |
end | number | The end of the range. |
Returns:value between 0 and 1, representing where the "value" parameter falls within the range defined by start and end
- Type:
- number
Example | invertedLerp(-10, 0, 10); |
| invertedLerp(0, 0, 10); |
| invertedLerp(5, 0, 10); |
| invertedLerp(10, 0, 10); |
| invertedLerp(100, 0, 10); |
(static) isDecimal(number) → {boolean}#
Checks if a number is a decimal by verifying if it has a fractional part.
Parameters:Name | Type | Description |
---|
number | number | The number to check. |
Returns:Returns true if the number is a decimal, false otherwise.
- Type:
- boolean
Example | isDecimal(1.5); |
| isDecimal(1); |
(static) isEven(number) → {boolean}#
Check is the given number is a EVEN number
Parameters:Name | Type | Description |
---|
number | number | The number to check |
(static) isMultipleOf(dividend, divisor) → {boolean}#
Check is a number is multiple of other
Parameters:Name | Type | Description |
---|
dividend | number | the number check is multiple |
divisor | number | divisor number |
Example | isMultipleOf(1, 2); |
| isMultipleOf(1, 1); |
| isMultipleOf(10, 2); |
| isMultipleOf(0, 2); |
| isMultipleOf(0, 0); |
| isMultipleOf(7, 21); |
| isMultipleOf(100, 21); |
| isMultipleOf(15, 5); |
| isMultipleOf(14, 5); |
(static) isNarcissisticNumber(n) → {boolean}#
A Narcissistic Number is a number of length l in which the sum of its digits to the power of l is equal to the original number. If this seems confusing, refer to the example below.
Ex: 153, where l = 3 ( the number of digits in 153 ) 13 + 53 + 33 = 153
Parameters:Name | Type | Description |
---|
n | number | number to check if a narcissistic |
Example | isNarcissistic(153); |
| isNarcissistic(1); |
| isNarcissistic(435); |
| isNarcissistic(370); |
| isNarcissistic(324); |
| isNarcissistic(371); |
| isNarcissistic(4328); |
| isNarcissistic(407); |
| isNarcissistic(3248); |
(static) isOdd(number) → {boolean}#
Check is the given number is a ODD number
Parameters:Name | Type | Description |
---|
number | number | The number to check |
(static) isValidNumber(number)#
Check if the given value is a valid number
Parameters:Name | Type | Description |
---|
number | number | number to validate |
Example | isValidNumber(42); |
| isValidNumber(0); |
| isValidNumber(-1); |
| isValidNumber(3.14); |
| isValidNumber(NaN); |
| isValidNumber(null); |
| isValidNumber(); |
| isValidNumber("42"); |
(static) lerp(value, min, max) → {number}#
Return the value between 2 values based on a given percentage (decimal midpoint) using linear interpolation.
Parameters:Name | Type | Description |
---|
value | number | The decimal value used for interpolation |
min | number | The minimum value |
max | number | The maximum value |
Returns:The result of the interpolation
- Type:
- number
Example | lerp(0, 0, 100); |
| lerp(0.5, 0, 100); |
| lerp(1, 0, 100); |
(static) map(value, fromRangeStart, fromRangeEnd, toRangeStart, toRangeEnd) → {number}#
Re-maps a number from one range to another
Parameters:Name | Type | Description |
---|
value | number | The number to be re-mapped |
fromRangeStart | number | The start of the range the number is currently in |
fromRangeEnd | number | The end of the range the number is currently in |
toRangeStart | number | The start of the range the number should be mapped to |
toRangeEnd | number | The end of the range the number should be mapped to |
Example | |
| map(-10, 0, 100, 0, 1000) |
| map(0, 0, 100, 0, 1000) |
| map(10, 0, 100, 0, 1000) |
| map(50, 0, 100, 0, 1000) |
| map(1000, 0, 100, 0, 1000) |
Returns the median of the givens numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| the numbers to get the median |
(static) mode(args) → {*}#
Returns the most repeated element in an array
Parameters:Name | Type | Description |
---|
args | Array | the elements to get the mode |
Example | mode([1, 2, 2, 3, 4]); |
| mode(["apple", "banana", "banana", "cherry"]); |
(static) multiplication(…numbers) → {number}#
Calculates the product of all given numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| The numbers to be multiplied |
Returns:The product of all given numbers
- Type:
- number
Example | multiplication(1, 2); |
| multiplication(1, 2, -5, 2.4, -6.5, 0.5); |
| multiplication(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); |
| multiplication(-1, 2, 3, 4, 5, 6, 7, 8, -9); |
| multiplication(...[-1, 2, 3, 4, 5, 6, 7, 8, -9]); |
(static) negative(number) → {number}#
Converts the given number to its negative equivalent, unless it's already negative or zero.
Parameters:Name | Type | Description |
---|
number | number | The number to be converted |
Returns:- The negative equivalent of the input number, or 0 if the input was 0.
- Type:
- number
Example | negative(10) |
| negative(0) |
| negative(-5) |
(static) percentage(value, total) → {number}#
Calculates the percentage of a given value in relation to a total value
Parameters:Name | Type | Description |
---|
value | number | The value to be calculated as a percentage |
total | number | The total value to be used as reference |
Returns:The calculated percentage
- Type:
- number
Example | percentage(10, 100); |
| percentage(40, 40); |
| percentage(40, 20); |
(static) radiansToDegrees(r) → {number}#
Converts a given radian value to degrees
Parameters:Name | Type | Description |
---|
r | number | The radian value to be converted to degrees |
Returns:The converted radian value in degrees
- Type:
- number
Example | radiansToDegrees(1.58) |
| radiansToDegrees(2.5) |
(static) range(start, end, stepopt, skipopt) → {Array.<number>}#
Returns an array of numbers between the start
and end
parameters, incrementing by the step
parameter. Optionally, the values within the specified skip
range can be skipped.
Parameters:Name | Type | Attributes | Default | Description |
---|
start | number | | | The starting point of the range |
end | number | | | The ending point of the range |
step | number | <optional>
| 1 | The increment value |
skip | Array.<{start: number, end: number}> | <optional>
| [] | The range of values to skip |
Returns:- Type:
- Array.<number>
Example | range(1, 5); |
| range(0, 100, 10); |
| range(0, 100, 100) |
| range(1, 100, 100) |
| range(0, 10, 1, [{start:2, end:8}]) |
| range(0, 10, 1, [{start:2, end:4}, {start:7, end:8}]) |
(static) roundNumber(num, maxOfDecimalsopt) → {number}#
Rounds a number to a specified maximum number of decimals.
Parameters:Name | Type | Attributes | Default | Description |
---|
num | number | | | The number to round. |
maxOfDecimals | number | <optional>
| 2 | The maximum number of decimals to round to. Defaults to 2 if not provided. |
Throws:- If the
num
parameter is not a number.
- Type
- TypeError
- If the
maxOfDecimals
parameter is not a number.
- Type
- TypeError
- If the
maxOfDecimals
parameter is less than 0
- Type
- RangeError
(static) subtraction(…numbers) → {number}#
Calculates a subtraction of all givens numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| the numbers to subtraction |
Examples | subtraction(1,2,-5,2.4,-6.5,0.5); |
| subtraction(1,2,3,4,5,6,7,8,9,0); |
| subtraction(-1,2,3,4,5,6,7,8,-9); |
| subtraction(...[-1,2,3,4,5,6,7,8,-9]); |
(static) sum(…numbers) → {number}#
Calculates a sum of all givens numbers
Parameters:Name | Type | Attributes | Description |
---|
numbers | number | <repeatable>
| the numbers to sum |
Examples | sum(1,2,3,4,5,6,7,8,9,0); |
| sum(-1,2,3,4,5,6,7,8,-9); |
| sum(...[-1,2,3,4,5,6,7,8,-9]); |