ColdFusion UDF Library - listSwitch
December 16th, 2008
«« Back to ColdFusion Library
Category:
LIST
Description:
Swaps the position of items in a list
Parameters:
Returns:
Requires:
Sample Use:
Copy to Clipboard
Category:
LIST
Description:
Swaps the position of items in a list
Parameters:
- list (List, required)
The list you wish to work with - pos1 (Numeric, required)
The index of the first item - pos2 (Numeric, required)
The index of the second item - delimeter (String, Default: ,)
the list delimeter
Returns:
Requires:
Sample Use:
Copy to Clipboard
function listSwitch(list,pos1,pos2){
var temp = "";
var delimiter = ",";
if (ArrayLen(arguments) gte 2)delimiter = arguments[2];
temp = ListGetAt(list,pos1,delimiter);
list = ListSetAt(list,pos1,ListGetAt(list,pos2,delimiter),delimiter);
list = ListSetAt(list,pos2,temp,delimiter);
return list;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=31&function=listSwitch




This could be used to implement various sorting algorithms on your lists. (assuming the native listSort() did not meet your needs)