ColdFusion UDF Library - listNear
December 16th, 2008
«« Back to ColdFusion Library
Category:
LIST
Description:
Searches in a list for a matching value or the closest matching value.
Parameters:
Returns:
(Numeric) The position in the list which is the closest match to the value passed.
Requires:
Sample Use:
Copy to Clipboard
Category:
LIST
Description:
Searches in a list for a matching value or the closest matching value.
Parameters:
- list (List, required)
The list which to search for the closest match of value in. - value (Numeric, required)
The number to find the closest match of in list. - delimeter (String, Default: ,)
The delimiter used in list.
Returns:
(Numeric) The position in the list which is the closest match to the value passed.
Requires:
Sample Use:
Copy to Clipboard
function listNear(list,value){
var loop = 0;
var pos = 0;
var distance = -1;
var delimiter = ",";
if (arrayLen(arguments) gte 3)delimiter = arguments[3];
for (loop = 1; loop lte listLen(list,delimiter); loop = incrementValue(loop)){
if (abs(value-listGetAt(list,loop,delimiter)) lt distance or distance lt 0){
pos = loop;
distance = abs(value-listGetAt(list,loop,delimiter));
};
};
return pos;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=35&function=listNear



