b5e0e55d7b70d61608f28ead2ac64be5c117aec9
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / partition.js
1 var createAggregator = require('./_createAggregator');
2
3 /**
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).
8  *
9  * @static
10  * @memberOf _
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.
15  * @example
16  *
17  * var users = [
18  *   { 'user': 'barney',  'age': 36, 'active': false },
19  *   { 'user': 'fred',    'age': 40, 'active': true },
20  *   { 'user': 'pebbles', 'age': 1,  'active': false }
21  * ];
22  *
23  * _.partition(users, function(o) { return o.active; });
24  * // => objects for [['fred'], ['barney', 'pebbles']]
25  *
26  * // The `_.matches` iteratee shorthand.
27  * _.partition(users, { 'age': 1, 'active': false });
28  * // => objects for [['pebbles'], ['barney', 'fred']]
29  *
30  * // The `_.matchesProperty` iteratee shorthand.
31  * _.partition(users, ['active', false]);
32  * // => objects for [['barney', 'pebbles'], ['fred']]
33  *
34  * // The `_.property` iteratee shorthand.
35  * _.partition(users, 'active');
36  * // => objects for [['fred'], ['barney', 'pebbles']]
37  */
38 var partition = createAggregator(function(result, value, key) {
39   result[key ? 0 : 1].push(value);
40 }, function() { return [[], []]; });
41
42 module.exports = partition;