Created
February 18, 2012 02:44
-
-
Save bittersweetryan/1857045 to your computer and use it in GitHub Desktop.
map in coldfusion zeus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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