Skip to content

Instantly share code, notes, and snippets.

@DaveAtDog
Last active August 29, 2015 14:00
Show Gist options
  • Save DaveAtDog/11395646 to your computer and use it in GitHub Desktop.
Save DaveAtDog/11395646 to your computer and use it in GitHub Desktop.
Match method to replicated the functionality of AS3’s Dictionary Class.
// Define our relationships
var map = {};
map[THING] = RELATED_THING;
// match method — searches for key and reurns value if not searches for value and returns key otherwise returns undefined.
var match = function(value)
{
if (map.hasOwnProperty(value))
{
return map[value];
}
else
{
for (var item in map)
{
if (map[item] === value)
{
return item;
}
}
return undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment