Created
February 1, 2013 02:16
-
-
Save junosuarez/4688640 to your computer and use it in GitHub Desktop.
_.last predicate signature use case
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
//rather than: | |
var title = ''; | |
for(var i = things.length-1; i >= 0; i--) { | |
title = things[i].title; | |
if (title) { | |
break; | |
} | |
} | |
// I wanna do: | |
var title = _.last(things, function (thing) { return thing.title; }).title | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/cc @jdalton