Last active
August 29, 2015 14:13
-
-
Save tonyjunkes/9ac2b9fb142685e5d9cb to your computer and use it in GitHub Desktop.
Entry for Adam Cameron's puzzle - http://blog.adamcameron.me/2015/01/another-quick-code-puzzle-any-language.html
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> | |
set = { | |
one : { | |
alphabet : "a", | |
maori : "tahi", | |
roman : "i", | |
ordinal : "first" | |
}, | |
two : { | |
alphabet : "b", | |
maori : "rua", | |
roman : "ii", | |
ordinal : "second" | |
}, | |
three : { | |
alphabet : "c", | |
maori : "toru", | |
roman : "iii", | |
ordinal : "third" | |
}, | |
four : { | |
alphabet : "d", | |
maori : "wha", | |
roman : "iv", | |
ordinal : "fourth" | |
} | |
}; | |
subset = ["four", "two"]; | |
public array function getOrderedSubset(required struct set, required array subset) | |
output="false" | |
{ | |
return subset.filter(function(e) { | |
return structKeyExists(set, e); | |
}).map(function(v, i) { | |
set[v].label = v; | |
return set[v]; | |
}); | |
} | |
writeDump(getOrderedSubset(set, subset)); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment