Skip to content

Instantly share code, notes, and snippets.

@adam-lynch
Last active August 29, 2015 13:57
Show Gist options
  • Save adam-lynch/9820474 to your computer and use it in GitHub Desktop.
Save adam-lynch/9820474 to your computer and use it in GitHub Desktop.
A (probably inefficient) functional approach to determine if any object contains a specific value for a property in an array of objects. Very Haskelly.
var existsInAny = function(needle, propertyName, haystack){
return haystack.map(function(el){return el[propertyName] === needle;}).reduce(function(a,b){return a||b;});
}
/*
# CoffeeScript version
existsInAny = (needle, propertyName, haystack) ->
haystack.map((el)-> el[propertyName] is needle).reduce((a,b)-> a||b)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment