Last active
August 29, 2015 14:00
-
-
Save pgilad/11093988 to your computer and use it in GitHub Desktop.
Check if a collection has truthy values for keys
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
//to validate if a collection has all the desired keys and they are truthy: | |
var hasEvery = function(desiredKeys, collection) { | |
return _.all(desiredKeys, _.result.bind(collection, collection)); | |
}; | |
var desiredKeys = ['hello', 'there', 'isIt']; | |
var collection = { hello: 1, there: 1, isIt: true}; | |
hasEvery(desiredKeys, collection); | |
//-> true | |
collection.isIt = false; | |
hasEvery(desiredKeys, collection); | |
//-> false | |
desiredKeys = ['hello', 'me']; | |
hasEvery(desiredKeys, collection); | |
//-> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment