You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

ds_list_range

Returns the range of the values in a list.

ds_list_range(list)
Returns the range of the values in a list.
COPY/// @func   ds_list_range(list)
///
/// @desc   Returns the range of the values in a list.
///         If the list is empty, undefined is returned.
///
/// @param  {list}      list        list data structure
///
/// @return {real}      range of values
///
/// GMLscripts.com/license

function ds_list_range(list)
{
    var n = ds_list_size(list);
    if (n == 0) return undefined;

    var maxv = ds_list_find_value(list, 0);
    var minv = maxv;

    for (var i=1; i<n; i++) {
        var val = ds_list_find_value(list, i);
        maxv = max(maxv, val);
        minv = min(minv, val);
    }

    return (maxv - minv);
}

Contributors: Quimp

GitHub: View · Commits · Blame · Raw