Skip to content

Instantly share code, notes, and snippets.

@stackdumper
Created March 18, 2018 20:08
Show Gist options
  • Save stackdumper/3f2f374e635a0b8a2e3002270c5fc44b to your computer and use it in GitHub Desktop.
Save stackdumper/3f2f374e635a0b8a2e3002270c5fc44b to your computer and use it in GitHub Desktop.
2d object normalization
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