TryCF Gist
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> | |
// credit: Adam Cameron via http://blog.adamcameron.me/2014/02/coldfusion-11-member-functions.html (with a few tweaks) | |
s = "The"; | |
s = s.listAppend("quick brown fox", " ") | |
.listAppend("jumps over the lazy dog", " ") | |
.ucase() | |
.reverse(); | |
writeOutput(s); | |
// credit: Adam Cameron via http://blog.adamcameron.me/2014/02/coldfusion-11-map-and-reduce.html | |
a = [1]; | |
a[3] = 3; | |
writeDump(a); | |
result = a.map(function(v,i,a){ | |
if (structKeyExists(arguments, "v")){ | |
return v^2; | |
} | |
}); | |
writeDump(result); | |
result = a.map(function(v=0,i,a){ | |
return v^2; | |
}); | |
writeDump(result); | |
//.... | |
original = {"one"={1="tahi"},"two"={2="rua"},"three"={3="toru"},"four"={4="wha"}}; | |
fixed = structMap(original, function(k,v){ | |
return v[v.keyList().listFirst()]; | |
}); | |
writeDump([original,fixed]); | |
fixed = original.map(function(k,v){ | |
return v.keyList().listFirst(); | |
}); | |
writeDump([original,fixed]); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment