1 | import arrayFilter from './_arrayFilter';
|
2 | import baseFilter from './_baseFilter';
|
3 | import baseIteratee from './_baseIteratee';
|
4 | import isArray from './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 | * @since 0.1.0
|
13 | * @category Collection
|
14 | * @param {Array|Object} collection The collection to iterate over.
|
15 | * @param {Array|Function|Object|string} [predicate=_.identity]
|
16 | * The function invoked per iteration.
|
17 | * @returns {Array} Returns the new filtered array.
|
18 | * @example
|
19 | *
|
20 | * var users = [
|
21 | * { 'user': 'barney', 'age': 36, 'active': false },
|
22 | * { 'user': 'fred', 'age': 40, 'active': true }
|
23 | * ];
|
24 | *
|
25 | * _.reject(users, function(o) { return !o.active; });
|
26 | * // => objects for ['fred']
|
27 | *
|
28 | * // The `_.matches` iteratee shorthand.
|
29 | * _.reject(users, { 'age': 40, 'active': true });
|
30 | * // => objects for ['barney']
|
31 | *
|
32 | * // The `_.matchesProperty` iteratee shorthand.
|
33 | * _.reject(users, ['active', false]);
|
34 | * // => objects for ['fred']
|
35 | *
|
36 | * // The `_.property` iteratee shorthand.
|
37 | * _.reject(users, 'active');
|
38 | * // => objects for ['barney']
|
39 | */
|
40 | function reject(collection, predicate) {
|
41 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
42 | predicate = baseIteratee(predicate, 3);
|
43 | return func(collection, function(value, index, collection) {
|
44 | return !predicate(value, index, collection);
|
45 | });
|
46 | }
|
47 |
|
48 | export default reject;
|