mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Consolidate aggregate modules.
This commit is contained in:
11
partition.js
11
partition.js
@@ -1,4 +1,4 @@
|
||||
import createAggregator from './.internal/createAggregator.js';
|
||||
import reduce from './reduce.js';
|
||||
|
||||
/**
|
||||
* Creates an array of elements split into two groups, the first of which
|
||||
@@ -19,10 +19,13 @@ import createAggregator from './.internal/createAggregator.js';
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* ];
|
||||
*
|
||||
* partition(users, o => o.active);
|
||||
* partition(users, ({ active }) => active);
|
||||
* // => objects for [['fred'], ['barney', 'pebbles']]
|
||||
*/
|
||||
const partition = createAggregator((result, value, key) =>
|
||||
result[key ? 0 : 1].push(value), () => [[], []]);
|
||||
function partition(collection, predicate) {
|
||||
return reduce(collection, (result, value, key) => (
|
||||
result[key ? 0 : 1].push(value)
|
||||
), [[], []]);
|
||||
}
|
||||
|
||||
export default partition;
|
||||
|
||||
Reference in New Issue
Block a user