CFLib.org – Common Function Library Project

getRange(samples)

Last updated July 25, 2013

author

Rodell Basalo

Version: 1 | Requires: CF9 | Library: CFMLLib

Description:
STATISTICS - The range is the size of the smallest interval which contains all the data and provides an indication of statistical dispersion. It is measured in the same units as the data. Since it only depends on two of the observations, it is most useful in representing the dispersion of small data sets.

Return Values:
Returns a numeric value that is the range of the samples

Example:

<cfset samples = [1,2,3,4,5,6,1,2,4,45,5,6,89,7,7,8,12,8,99,7,7,8,8,8]>
<cfset range = getRange(samples)>
<cfoutput>#range#</cfoutput>

Parameters:

Name Description Required
samples Array of values to return range for Yes

Full UDF Source:

/**
 * Gets the difference between the largest and smallest values in a given data set (statistics)
 * v0.9 by Rodell Basalo
 * v1.0 by Adam Cameron (simplified logic)
 * 
 * @param samples      Array of values to return range for (Required)
 * @return Returns a numeric value that is the range of the samples 
 * @author Rodell Basalo (delroekid@gmail.com) 
 * @version 1.0, July 25, 2013 
 */
numeric function getRange(required array samples){
    if (arrayIsEmpty(arguments.samples)){
        throw(type="IllegalArgumentException", message="sample argument is empty", detail="The sample array must contain at least one element");
    }
    return arrayMax(arguments.samples) - arrayMin(arguments.samples);
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson