CFLib.org – Common Function Library Project

listFindMissing(list[, delim])

Last updated July 20, 2005

author

Giampaolo Bellavite

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Return a list with missing integers in a list of consequential numbers, starting from the minimum integer in the list and ending to the maximum one.

Return Values:
Returns a string.

Example:

<cfoutput>
#listFindMissing('1,2,3,6,7,8,10')#
</cfoutput>

Parameters:

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

Full UDF Source:

/**
 * Find missing integers in a list of consequential numbers.
 * 
 * @param list 	 List to check. (Required)
 * @param delim 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Giampaolo Bellavite (giampaolo@bellavite.com) 
 * @version 1, July 20, 2005 
 */
function listFindMissing(list) {
  var delim=","; // list delimiter
  var arrToSearch=""; 
  var i=0;
  var j=0;    
  var returnList="";
  if(arrayLen(arguments) GTE 2) delim = arguments[2];
  arrToSearch=listToArray(list,delim);
  for(i=ArrayMin(arrToSearch);i LTE arrayMax(arrToSearch);i=i+1)
    for(j=1;j LTE arrayLen(arrToSearch);j=j+1) 
      if(arrToSearch[j] EQ i)  break;
      else 
        if (j EQ arrayLen(arrToSearch))
          returnList = listAppend(returnList,i,delim);
  return returnList;
}
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