Last active
August 29, 2015 13:57
-
-
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.
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 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