Global

Methods

average(nums) → {number|NaN}

Calculates the average of all elements in an array.
Parameters:
Name Type Description
nums Array.<number> The array of numbers to calculate the average.
Source:
Throws:
- Thrown if the array is empty or not an array of numbers.
Type
ErrorInvalidArgument
Returns:
- The average value of the array.
Type
number | NaN
Examples
// Returns 2.5
average([1, 2, 3, 4]);
// Throws ErrorInvalidArgument
average([]);

median(nums) → {number}

Calculates the median of all elements in an array.
Parameters:
Name Type Description
nums Array.<number> The array of numbers to calculate the median.
Source:
Throws:
- Thrown if the input is not an array of numbers.
Type
ErrorInvalidArgument
Returns:
- The median value of the array.
Type
number
Examples
// Returns 3
median([1, 3, 5]);
// Returns 2.5
median([1, 2, 3, 4]);

sum(nums) → {number}

Sums all elements in an array.
Parameters:
Name Type Description
nums Array.<number> The array of numbers to sum.
Source:
Throws:
- Thrown if the input is not an array of numbers.
Type
ErrorInvalidArgument
Returns:
- The total sum of the array elements.
Type
number
Examples
// Returns 10
sum([1, 2, 3, 4]);
// Throws ErrorInvalidArgument
sum("not an array");