-
-
Save alexbeletsky/9813103 to your computer and use it in GitHub Desktop.
Which is better
This file contains 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
// which is better? | |
function f() { | |
// returns object.. takes some cpu to complete | |
} | |
// this one? | |
return f().one || f().two; | |
// that one? | |
var p = f(); | |
return p.one || p.two; | |
// or that one? | |
return either(fc(), 'one', 'two'); | |
function either() { | |
var o = arguments[0]; | |
var p = Array.prototype.slice.call(arguments, 1); | |
return p.reduce(function (p, c) { | |
return o[p] || o[c]; | |
}); | |
} |
This file contains 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
var titles = Object.keys(grouped).map(function (key) { | |
return { name: 'BEST_OF_' + key.toUpperCase() + '_TITLE', content: either(_.first(grouped[key]), 'title', 'authorName') }; | |
}); | |
var descriptions = Object.keys(grouped).map(function (key) { | |
return { name: 'BEST_OF_' + key.toUpperCase() + '_DESCRIPTION', content: _.first(grouped[key]).description }; | |
}); |
This file contains 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
function either() { | |
var o = arguments[0]; | |
var p = Array.prototype.slice.call(arguments, 1); | |
return p.reduce(function (p, c) { | |
return o[p] || o[c]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment