Created
March 18, 2018 20:08
-
-
Save stackdumper/3f2f374e635a0b8a2e3002270c5fc44b to your computer and use it in GitHub Desktop.
2d object normalization
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
const normalizeMap = (map, min, max) => { | |
const keys = Object.keys(map); | |
const values = Object.values(map); | |
let normalizedValues; | |
if (typeof values[0] === "object") { | |
normalizedValues = values.map(v => normalizeMap(v, min, max)); | |
} else { | |
normalizedValues = normalizeArray(values, min, max); | |
} | |
const normalizedMap = normalizedValues.reduce((acc, curr, i) => { | |
acc[keys[i]] = curr; | |
return acc; | |
}, {}) | |
return normalizedMap; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment