Last active
August 29, 2015 14:00
-
-
Save DaveAtDog/11395646 to your computer and use it in GitHub Desktop.
Match method to replicated the functionality of AS3’s Dictionary Class.
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
// 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