Created
November 24, 2016 09:32
-
-
Save kiinlam/91014d414a88050b030b776c4f18bdf5 to your computer and use it in GitHub Desktop.
mapToObj, mapToObjArray, objToMap
This file contains hidden or 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 mapToObj (map) { | |
let obj = Object.create(null) | |
for (let [k,v] of map) { | |
obj[k] = v | |
} | |
return obj | |
} | |
function mapToObjArray (map) { | |
let objArray = [] | |
for (let [k,v] of map) { | |
objArray.push({ | |
[k]: v | |
}) | |
} | |
return objArray | |
} | |
function objToMap(obj) { | |
let map = new Map() | |
for (let k of Object.keys(obj)) { | |
map.set(k, obj[k]) | |
} | |
return map | |
} | |
module.exports = { | |
mapToObj, | |
mapToObjArray, | |
objToMap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment