Sum()Method : JMath
Calculates the sum of a variable amount of numbers
Values
function Sum(...values: Number): Number
Parameters
- values
- A variable length Array which can be passed any amount of numbers.
- Has no default value - required
Returns
- Number
- The sum of all passed parameters.
Common Errors
- TypeError: At least 1 parameter is not a number or float
- Often occurs when values is accidentaly passed an Array.
Example
const sum = JMath.Sum(3, 8, 1, 9, 3, 8, 25); // Should return: 57
Notes
- This method is probably most useful when Array deconstruction is used to dynamically pass a larger collection of numbers.
Log
JMAC a | 17-05-25
Method introduced.
JMAC b | 21-05-25
Method seperated from Average(), error catch fixed.
JMAC g_a | 02-07-25
Method converted to Cast structure as test phase.
JMAC 1a | 02-09-25
Method reverted to normal structure.
Error fixes.