Skip to content

Instantly share code, notes, and snippets.

@mageowl
Last active May 24, 2021 23:29
Show Gist options
  • Select an option

  • Save mageowl/f7d74320e394fc6893528d7ac74df456 to your computer and use it in GitHub Desktop.

Select an option

Save mageowl/f7d74320e394fc6893528d7ac74df456 to your computer and use it in GitHub Desktop.
Array map on objects.
function omap(object, cb) {
return Object.fromEntries(Object.entries(object).map(cb));
}
const mappable = {
map(cb) {return omap(this, cb)}
}
const abc = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
// ...
__proto__: mappable
}
abc.map(([key, value]) => [key, value + 10]) //=> {a: 11, b: 12, c: 13, d: 14, e: 15, ...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment