forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreject.js
30 lines (28 loc) · 924 Bytes
/
reject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import filter from './filter.js'
import filterObject from './filterObject.js'
import negate from './negate.js'
/**
* The opposite of `filter` this method returns the elements of `collection`
* that `predicate` does **not** return truthy for.
*
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
* @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, filter
* @example
*
* const users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false }
* ]
*
* reject(users, ({ active }) => active)
* // => objects for ['fred']
*/
function reject(collection, predicate) {
const func = Array.isArray(collection) ? filter : filterObject
return func(collection, negate(predicate))
}
export default reject