Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / collection / reject.js
1 var arrayFilter = require('../internal/arrayFilter'),
2     baseCallback = require('../internal/baseCallback'),
3     baseFilter = require('../internal/baseFilter'),
4     isArray = require('../lang/isArray');
5
6 /**
7  * The opposite of `_.filter`; this method returns the elements of `collection`
8  * that `predicate` does **not** return truthy for.
9  *
10  * @static
11  * @memberOf _
12  * @category Collection
13  * @param {Array|Object|string} collection The collection to iterate over.
14  * @param {Function|Object|string} [predicate=_.identity] The function invoked
15  *  per iteration.
16  * @param {*} [thisArg] The `this` binding of `predicate`.
17  * @returns {Array} Returns the new filtered array.
18  * @example
19  *
20  * _.reject([1, 2, 3, 4], function(n) {
21  *   return n % 2 == 0;
22  * });
23  * // => [1, 3]
24  *
25  * var users = [
26  *   { 'user': 'barney', 'age': 36, 'active': false },
27  *   { 'user': 'fred',   'age': 40, 'active': true }
28  * ];
29  *
30  * // using the `_.matches` callback shorthand
31  * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
32  * // => ['barney']
33  *
34  * // using the `_.matchesProperty` callback shorthand
35  * _.pluck(_.reject(users, 'active', false), 'user');
36  * // => ['fred']
37  *
38  * // using the `_.property` callback shorthand
39  * _.pluck(_.reject(users, 'active'), 'user');
40  * // => ['barney']
41  */
42 function reject(collection, predicate, thisArg) {
43   var func = isArray(collection) ? arrayFilter : baseFilter;
44   predicate = baseCallback(predicate, thisArg, 3);
45   return func(collection, function(value, index, collection) {
46     return !predicate(value, index, collection);
47   });
48 }
49
50 module.exports = reject;