Created
June 8, 2016 15:05
-
-
Save ryanwilsonperkin/c781181a56220da27947a64e7d464f6a to your computer and use it in GitHub Desktop.
Legibility vs Cleverness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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