Last active
August 29, 2015 14:24
-
-
Save ArtskydJ/b3be2ee43736b759e5d0 to your computer and use it in GitHub Desktop.
ColdFusion Snippets
This file contains 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> | |
function ArrayFilter(required array arr, required filterFn) { | |
var result = ArrayNew(1); | |
for (var i = 1; i <= ArrayLen(arr); i++) { | |
if (filterFn(arr[i])) { | |
ArrayAppend(result, arr[i]); | |
} | |
} | |
return result; | |
} | |
</cfscript> |
This file contains 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
<cffunction name="arrayify" access="private"> | |
<cfargument name="thing" type="any" required="true"> | |
<cfreturn (IsArray('thing')) ? thing : [thing]> | |
</cffunction> | |
<cfscript> | |
function arrayify(required any thing) { | |
return (IsArray('thing')) ? thing : [thing]; | |
} | |
</cfscript> |
This file contains 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> | |
function ArrayMap(required array arr, required mapFn) { | |
var result = ArrayNew(1); | |
for (var i = 1; i <= ArrayLen(arr); i++) { | |
ArrayAppend(result, mapFn(arr[i])); | |
} | |
return result; | |
} | |
</cfscript> |
This file contains 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> | |
function ArrayReduce(required array arr, required reduceFn, any memo) { | |
for (var i = 1; i <= ArrayLen(arr); i++) { | |
memo = reduceFn(memo, arr[i]); | |
} | |
return memo; | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment