e783fc7dd5e17f1b72896809a90fda92de0c3a0b
[platform/framework/web/crosswalk-tizen.git] /
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  * If a property name is provided for `predicate` the created `_.property`
11  * style callback returns the property value of the given element.
12  *
13  * If a value is also provided for `thisArg` the created `_.matchesProperty`
14  * style callback returns `true` for elements that have a matching property
15  * value, else `false`.
16  *
17  * If an object is provided for `predicate` the created `_.matches` style
18  * callback returns `true` for elements that have the properties of the given
19  * object, else `false`.
20  *
21  * @static
22  * @memberOf _
23  * @category Collection
24  * @param {Array|Object|string} collection The collection to iterate over.
25  * @param {Function|Object|string} [predicate=_.identity] The function invoked
26  *  per iteration.
27  * @param {*} [thisArg] The `this` binding of `predicate`.
28  * @returns {Array} Returns the new filtered array.
29  * @example
30  *
31  * _.reject([1, 2, 3, 4], function(n) {
32  *   return n % 2 == 0;
33  * });
34  * // => [1, 3]
35  *
36  * var users = [
37  *   { 'user': 'barney', 'age': 36, 'active': false },
38  *   { 'user': 'fred',   'age': 40, 'active': true }
39  * ];
40  *
41  * // using the `_.matches` callback shorthand
42  * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
43  * // => ['barney']
44  *
45  * // using the `_.matchesProperty` callback shorthand
46  * _.pluck(_.reject(users, 'active', false), 'user');
47  * // => ['fred']
48  *
49  * // using the `_.property` callback shorthand
50  * _.pluck(_.reject(users, 'active'), 'user');
51  * // => ['barney']
52  */
53 function reject(collection, predicate, thisArg) {
54   var func = isArray(collection) ? arrayFilter : baseFilter;
55   predicate = baseCallback(predicate, thisArg, 3);
56   return func(collection, function(value, index, collection) {
57     return !predicate(value, index, collection);
58   });
59 }
60
61 module.exports = reject;