CFLib.org – Common Function Library Project

rank(value, set)

Last updated December 04, 2008

author

Scott Fitchet

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Data validation and exception handling have been purposely omitted for speed. If you are not using the latest version of ColdFusion or Railo you might need to change "i++" to "i = i + 1".

Return Values:
Returns a number.

Example:

rank(3, "2,300,1,3,1")

Parameters:

Name Description Required
value Value to rank. Yes
set List of numbers. Yes

Full UDF Source:

/**
 * Ranks a number within a set.
 * 
 * @param value      Value to rank. (Required)
 * @param set      List of numbers. (Required)
 * @return Returns a number. 
 * @author Scott Fitchet (scott@figital.com) 
 * @version 1, December 4, 2008 
 */
function rank(value, set) {

    // Assume the value is in first place
    var ranking = 1;
    var i = 1;

    // Loop over each value in the set
    for (i = 1; i lte listlen(set); i=i+1 ) {
        // If this value in the set is greater, decrease the ordinal
        if ( listgetat(set, i) gt value ) ranking=ranking+1;
    }
    
    return ranking;
}

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