1
|
var arrayFilter = require('./_arrayFilter'),
|
2
|
baseFilter = require('./_baseFilter'),
|
3
|
baseIteratee = require('./_baseIteratee'),
|
4
|
isArray = require('./isArray'),
|
5
|
negate = require('./negate');
|
6
|
|
7
|
/**
|
8
|
* The opposite of `_.filter`; this method returns the elements of `collection`
|
9
|
* that `predicate` does **not** return truthy for.
|
10
|
*
|
11
|
* @static
|
12
|
* @memberOf _
|
13
|
* @since 0.1.0
|
14
|
* @category Collection
|
15
|
* @param {Array|Object} collection The collection to iterate over.
|
16
|
* @param {Function} [predicate=_.identity] The function invoked per iteration.
|
17
|
* @returns {Array} Returns the new filtered array.
|
18
|
* @see _.filter
|
19
|
* @example
|
20
|
*
|
21
|
* var users = [
|
22
|
* { 'user': 'barney', 'age': 36, 'active': false },
|
23
|
* { 'user': 'fred', 'age': 40, 'active': true }
|
24
|
* ];
|
25
|
*
|
26
|
* _.reject(users, function(o) { return !o.active; });
|
27
|
* // => objects for ['fred']
|
28
|
*
|
29
|
* // The `_.matches` iteratee shorthand.
|
30
|
* _.reject(users, { 'age': 40, 'active': true });
|
31
|
* // => objects for ['barney']
|
32
|
*
|
33
|
* // The `_.matchesProperty` iteratee shorthand.
|
34
|
* _.reject(users, ['active', false]);
|
35
|
* // => objects for ['fred']
|
36
|
*
|
37
|
* // The `_.property` iteratee shorthand.
|
38
|
* _.reject(users, 'active');
|
39
|
* // => objects for ['barney']
|
40
|
*/
|
41
|
function reject(collection, predicate) {
|
42
|
var func = isArray(collection) ? arrayFilter : baseFilter;
|
43
|
return func(collection, negate(baseIteratee(predicate, 3)));
|
44
|
}
|
45
|
|
46
|
module.exports = reject;
|