Skip to content

Instantly share code, notes, and snippets.

@ryanwilsonperkin
Created June 8, 2016 15:05
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 ryanwilsonperkin/c781181a56220da27947a64e7d464f6a to your computer and use it in GitHub Desktop.
Save ryanwilsonperkin/c781181a56220da27947a64e7d464f6a to your computer and use it in GitHub Desktop.
Legibility vs Cleverness
// Clever
function comprehension(arr, fn) {
return arr.reduce((obj, key) => Object.assign(obj, {[key]: fn(key)}), {});
}
// Legible
function comprehension(arr, fn) {
const obj = {};
for (key of arr) {
obj[key] = fn(key);
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment