Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.