-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (21 loc) · 703 Bytes
/
index.js
File metadata and controls
23 lines (21 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const distribute = require('./lib/distribute');
const split = require('./lib/split');
/**
* array-select Extract items from one array into two or more arrays by results of a provided function
* @param {Array} array
* @param {...Function} ...reducers
* @return {Array[]}
*/
module.exports = function arraySelect(array, ...reducers) {
if (!Array.isArray(array)) {
throw new TypeError(`array-select expected first argument to be an array, instead got ${array}`);
}
switch (reducers.length) {
case 0:
throw new Error('array-select could not find any filtering function');
case 1:
return split(array, ...reducers);
default:
return distribute(array, ...reducers);
}
};