Members
(constant) PI :number
Constant value representing π (pi).
Type:
- number
Example
console.log(PI); // 3.14
Methods
average(nums) → {number}
Calculates the average of all elements in a numeric array.
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number> | An array of numbers. |
Throws:
-
If the input array is empty or contains non-numeric values.
- Type
- ErrorInvalidArgument
Returns:
The average (mean) of the array elements.
- Type
- number
Example
average([1, 2, 3]); // returns 2
median(arr) → {number}
Calculates the median value from a numeric array.
Median is the middle value in an ordered list.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | An array of numbers. |
Throws:
-
If the input is not a valid non-empty numeric array.
- Type
- ErrorInvalidArgument
Returns:
The median value of the array.
- Type
- number
Example
median([1, 2, 3]); // returns 2
median([1, 2, 3, 4]); // returns 2.5
sum(arr) → {number}
Calculates the sum of all elements in a numeric array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | An array of numbers to sum. |
Returns:
The total sum of all elements in the array.
- Type
- number
Example
sum([1, 2, 3]); // returns 6