-
-
Save alecmce/4198110 to your computer and use it in GitHub Desktop.
// option 1 | |
private static const ABC:Object = {"a":null, "b":null, "c":null} | |
private function isABC(char:String):Boolean | |
{ | |
return char in ABC; | |
} | |
// option 2 | |
private static const ABC:Vector.<String> = new <String>["a","b","c"]; | |
private function isABC(char:String):Boolean | |
{ | |
return ABC.indexOf(char) != -1; | |
} | |
// option 3? - other than using an Array, assuming that the ABC list could grow so we're not going to hard-code values, what other options do we have? |
Option 2 for me.
Scholar but readable!
I'd go for 1 I think, although with the modification of {"a":true, "b":true, "c":true}
and just return ABC[char]
. Although I suspect that's a pointless implementation detail that misses the point of this question. I just can't help it :)
2 is more type-safe (and possibly more "engineering" AS idiomatic), and so perhaps less liable to have random bugs introduced by people new to the code.
On the other hand, if the main interface is isABC, are the implementation details that important?
Thanks for the feedback! I much prefer Dave's implementation with {"a":true, "b":true, "c":true} to #1. Always fun to ruminate on these details :)
Depends if speed is an issue. Object or dictionary access is going to be faster as its a hash map (thought i'm not sure about using "in"). Pretty sure indexOf just checks everything from the start index.
dictionary[key] !== undefined