CFLib.org – Common Function Library Project

rank(value, set)

Last updated December 4, 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson