Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created July 24, 2013 18:15
Show Gist options
  • Save Sigmus/6073041 to your computer and use it in GitHub Desktop.
Save Sigmus/6073041 to your computer and use it in GitHub Desktop.
function best(fun, coll) {
return _.reduce(coll, function(x, y) {
return fun(x, y) ? x : y
});
}
best(function(x,y) {
return x > y
}, [1,2,3,4,5]);
// 5
best(function(x, y) {
return x.age > y.age
}, [{name: 'Flavio', age: 37},{name:'Lenita', age:35}]);
// {name: 'Flavio', age: 37}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment