Skip to content

Instantly share code, notes, and snippets.

@dlmanning
Last active December 18, 2015 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlmanning/ae9d950420d791811dce to your computer and use it in GitHub Desktop.
Save dlmanning/ae9d950420d791811dce to your computer and use it in GitHub Desktop.
dispatch keyed values to keyed functions
const branchDispatch = (obj, table, defaultFn) =>
Object.entries(obj)
.map(([key, value]) =>
table[key] != null
? [key, table[key](value)]
: typeof defaultFn === 'function'
? [key, defaultFn(value)]
: [key, undefined]
)
.reduce((results, [key, value]) => {
results[key] = value
return results
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment