Skip to content

Instantly share code, notes, and snippets.

@busches
Created June 18, 2014 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save busches/7e4c8889427247b2fd33 to your computer and use it in GitHub Desktop.
Save busches/7e4c8889427247b2fd33 to your computer and use it in GitHub Desktop.
<cfscript>
data = ['a','b','a'];
counts = {};
for (datum in data) {
if (!structKeyExists(counts, datum)) {
counts[datum] = 0;
}
counts[datum] = counts[datum]++;
}
writeDump(counts); // all zeros
counts = {};
for (datum in data) {
if (!structKeyExists(counts, datum)) {
counts[datum] = 0;
}
counts[datum] = counts[datum] + 1;
}
writeDump(counts); // correct counts
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment