Consolidate aggregate modules.

This commit is contained in:
John-David Dalton
2017-01-11 12:26:35 -08:00
parent 3b4cbc70e7
commit d80077ed94
7 changed files with 36 additions and 93 deletions

View File

@@ -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;