Created
August 6, 2014 06:42
-
-
Save conradfr/ce078d44992fd1011c3c to your computer and use it in GitHub Desktop.
filterByValues underscore.js mixin
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
/** | |
* Filter a collection by a property and an array of values | |
* demo: http://jsfiddle.net/3Y95F/ | |
* | |
* @param {array|object} collection (of objects) | |
* @param {string} property | |
* @param {array} array of accepted values | |
* @returns {array|object} | |
*/ | |
_.mixin({ | |
'filterByValues': function(collection, property, values) { | |
return _.filter(collection, function(item) { | |
return _.contains(values, item[property]); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment