CFLib.org – Common Function Library Project

listFindMissing(list[, delim])

Last updated July 21, 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;
}

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