Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.42 KB

array_mean.md

File metadata and controls

37 lines (26 loc) · 1.42 KB

Home > Community Toolbox Reference > Array utilities > Number array statistics

array_mean

Go to source

Returns the average value of numbers in the array or its subsection. If the array/subsection is empty, 0 is returned.

Arguments
Argument Type Usage Description
array Array<Real> Required The array to get the mean value of.
offset Real Default: 0 The starting index of the subsection (for a negative offset, it will count from array end).
length Real Default: undefined The length of the subsection (for a negative length, it will count backwards from the offset position).
Returns

Real

Example

The following code finds the mean level in the party:

var _heroes = [
    { name: "Alice", level: 14, gold: 165 },
    { name: "Bob", level: 16, gold: 546 },
    { name: "Charlie", level: 9, gold: 1753 },
    ];
var _levels = array_map(_heroes, function(_hero) { return _hero.level; });
var _mean_level = array_mean(_levels);
show_debug_message(_mean_level);

Update history

  • 23.4.0 - Created a function to calculate the average value of the numbers array values.