Created
December 15, 2013 23:51
-
-
Save elycruz/7980005 to your computer and use it in GitHub Desktop.
Gist for generating a map from an array of arrays [['a': 'hello'], ['b': 'world']].
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
function fromArrayMap (arrayMap, convertAllArrays) { | |
convertAllArrays = convertAllArrays || true; | |
var map = new Map(), value; | |
arrayMap.forEach(function(x) { | |
value = Array.isArray(x[1]) ? fromArrayMap(x[1]) : x[1]; | |
map.set(x[0], value); | |
}); | |
return map; | |
} | |
Map.prototype.fromArrayMap = fromArrayMap; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment