1df81c4cc7a295621849878499dfa1da34a62011
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / filter.js
1 var arrayFilter = require('./_arrayFilter'),
2     baseFilter = require('./_baseFilter'),
3     baseIteratee = require('./_baseIteratee'),
4     isArray = require('./isArray');
5
6 /**
7  * Iterates over elements of `collection`, returning an array of all elements
8  * `predicate` returns truthy for. The predicate is invoked with three arguments:
9  * (value, index|key, collection).
10  *
11  * @static
12  * @memberOf _
13  * @category Collection
14  * @param {Array|Object} collection The collection to iterate over.
15  * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
16  * @returns {Array} Returns the new filtered array.
17  * @example
18  *
19  * var users = [
20  *   { 'user': 'barney', 'age': 36, 'active': true },
21  *   { 'user': 'fred',   'age': 40, 'active': false }
22  * ];
23  *
24  * _.filter(users, function(o) { return !o.active; });
25  * // => objects for ['fred']
26  *
27  * // The `_.matches` iteratee shorthand.
28  * _.filter(users, { 'age': 36, 'active': true });
29  * // => objects for ['barney']
30  *
31  * // The `_.matchesProperty` iteratee shorthand.
32  * _.filter(users, ['active', false]);
33  * // => objects for ['fred']
34  *
35  * // The `_.property` iteratee shorthand.
36  * _.filter(users, 'active');
37  * // => objects for ['barney']
38  */
39 function filter(collection, predicate) {
40   var func = isArray(collection) ? arrayFilter : baseFilter;
41   return func(collection, baseIteratee(predicate, 3));
42 }
43
44 module.exports = filter;