CFLib.org – Common Function Library Project

listFindMaxOccurance(list[, delim])

Last updated February 23, 2005

author

Qasim Rasheed

Version: 2 | Requires: CF5 | Library: StrLib

Description:
This function will return the item with the most occurances in a list.

Return Values:
Returns a string.

Example:

<cfset list = "A1,A2,A3,A1,A3,A1,A2,A1,A1">
<cfset temp = listFindMaxOccurance(list)>
<cfdump var="#temp#">

Parameters:

Name Description Required
list The list to check. Yes
delim List delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * This function will return the item with the most occurances in a list.
 * V2 by Raymond Camden
 * 
 * @param list 	 The list to check. (Required)
 * @param delim 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Qasim Rasheed (qasimrasheed@hotmail.com) 
 * @version 2, February 23, 2005 
 */
function listFindMaxOccurance(list){
	var i = "";
	var delim = ",";
	var maxitem = "";
	var maxcount = 0;
	var thisItem = "";
	if(arrayLen(arguments) gte 2) delim = arguments[2];
		
	for(i=1;i lte listLen(list,delim );i=i+1) {
		thisItem = listGetAt(list,i,delim);
		if(listValueCount(list,thisItem,delim) gt maxcount) {
			maxcount = listValueCount(list,thisItem,delim);
			maxitem = thisItem;
		}
	}
	return maxitem;
}
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