Created
February 28, 2019 13:55
-
-
Save skamenetskiy/247ffe509930c8d2f9a00d1f335bce05 to your computer and use it in GitHub Desktop.
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
/** | |
* @name mapToObject | |
* @desc Converts Map to Object | |
* @param {Map} map | |
* @returns {Object} | |
*/ | |
function mapToObject(map) { | |
return Object.assign(Object.create(null), ...[...map].map(v => ({ [v[0]]: v[1] }))); | |
} | |
/** | |
* @name objectToMap | |
* @desc Converts Object to Map | |
* @param {Object} obj | |
* @returns {Map} | |
*/ | |
function objectToMap(obj) { | |
return new Map([...Object.keys(obj).map(k => ([k, obj[k]]))]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment