UNPKG

933 BJavaScriptView Raw
1import { divide as divide$1 } from '@vect/columns-select';
2import { divide } from '@vect/vector-select';
3import { mapper } from '@vect/vector-mapper';
4import { slice } from '@analys/table-init';
5
6const NUM_ASC = (a, b) => a - b;
7
8/**
9 * Divide a table by fields
10 * @param {*[]} fields
11 * @return {{ pick:TableObject, rest:TableObject }} - mutated 'this' {head, rows}
12 */
13
14const tableDivide = function (fields) {
15 var _this, _this2;
16
17 /** @type {Table|TableObject} */
18 const rs = (_this = this, slice(_this));
19 /** @type {Table|TableObject} */
20
21 const pk = (_this2 = this, slice(_this2));
22 const {
23 head,
24 rows
25 } = this;
26 const indexes = mapper(fields, label => head.indexOf(label)).sort(NUM_ASC);
27 ({
28 pick: pk.head,
29 rest: rs.head
30 } = divide(head, indexes));
31 ({
32 pick: pk.rows,
33 rest: rs.rows
34 } = divide$1(rows, indexes));
35 return {
36 pick: pk,
37 rest: rs
38 };
39};
40
41export { tableDivide };