1 var createAggregator = require('./internal/createAggregator');
4 * Creates an array of elements split into two groups, the first of which
5 * contains elements `predicate` returns truthy for, the second of which
6 * contains elements `predicate` returns falsey for. The predicate is
7 * invoked with one argument: (value).
11 * @category Collection
12 * @param {Array|Object} collection The collection to iterate over.
13 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
14 * @returns {Array} Returns the array of grouped elements.
18 * { 'user': 'barney', 'age': 36, 'active': false },
19 * { 'user': 'fred', 'age': 40, 'active': true },
20 * { 'user': 'pebbles', 'age': 1, 'active': false }
23 * _.partition(users, function(o) { return o.active; });
24 * // => objects for [['fred'], ['barney', 'pebbles']]
26 * // using the `_.matches` iteratee shorthand
27 * _.partition(users, { 'age': 1, 'active': false });
28 * // => objects for [['pebbles'], ['barney', 'fred']]
30 * // using the `_.matchesProperty` iteratee shorthand
31 * _.partition(users, ['active', false]);
32 * // => objects for [['barney', 'pebbles'], ['fred']]
34 * // using the `_.property` iteratee shorthand
35 * _.partition(users, 'active');
36 * // => objects for [['fred'], ['barney', 'pebbles']]
38 var partition = createAggregator(function(result, value, key) {
39 result[key ? 0 : 1].push(value);
40 }, function() { return [[], []]; });
42 module.exports = partition;