Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Created February 18, 2012 02:44
Show Gist options
  • Save bittersweetryan/1857045 to your computer and use it in GitHub Desktop.
Save bittersweetryan/1857045 to your computer and use it in GitHub Desktop.
map in coldfusion zeus
<cfscript>
public Array function map(Array arr,Function fn)
output=false {
//this is the new array that will hold the results
//of applying the function to each element of the array
var ret = [];
//use the new for-in construct to loop through each
//item in the array
for(ele in arr){
//append the result of passing each element
//into the function argument
arrayAppend(ret,fn(ele));
}
//return the newly created array
return ret;
}
//create an array to be passed into the map function
firstNames = ["Ryan","Sheri","Ayden","Brenden"];
//create a variable to hold the result, and create a
//new function on the fly that will be applied to each
//element into the array
newNames = map(firstNames,function(ele){
return ele & " Anklam";
});
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment