Created
July 23, 2019 23:50
-
-
Save noahlt/94773e51fe21849d1c12110efb386222 to your computer and use it in GitHub Desktop.
Make a method to map a Map to an Object
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
Object.fromMap = function(m, f) { | |
var r = {}; | |
f = f || ((x, y) => [x, y]); | |
for (let [k, v] of m) { | |
[k, v] = f(k, v); | |
r[k] = v; | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment