Skip to content

Instantly share code, notes, and snippets.

@comnik
Last active May 4, 2018 20:25
Show Gist options
  • Save comnik/85d4984393a9121a24e7812042804d33 to your computer and use it in GitHub Desktop.
Save comnik/85d4984393a9121a24e7812042804d33 to your computer and use it in GitHub Desktop.
Clojure core.set thingies in JS
const selectKeys = (m, keys) => {
return keys.reduce((acc, k) => {
acc[k] = m[k];
return acc;
}, {});
}
const invertMap = (m) =>
Object.keys(m).reduce((acc, k) => {
acc[m[k]] = k;
return acc;
}, {})
const renameKeys = (m, keyMap) =>
Object.keys(m).reduce((acc, k) => {
if (keyMap.hasOwnProperty(k)) {
acc[keyMap[k]] = m[k];
} else {
acc[k] = m[k];
}
return acc;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment