1 | /**
|
2 | * @param {Object<str,function(*):boolean>} filterObject
|
3 | * @return {Table|TableObject} - mutated 'this' {head, rows}
|
4 | */
|
5 | const tableFind = function (filterObject) {
|
6 | for (let field in filterObject) if (filterObject.hasOwnProperty(field)) tableFindOnce.call(this, field, filterObject[field]);
|
7 |
|
8 | return this;
|
9 | };
|
10 | /**
|
11 | * @param {str} field
|
12 | * @param {function(*):boolean} filter
|
13 | * @return {Table|TableObject} - mutated 'this' {head, rows}
|
14 | */
|
15 |
|
16 | const tableFindOnce = function (field, filter) {
|
17 | let j = this.head.indexOf(field);
|
18 | if (j >= 0) this.rows = this.rows.filter(row => filter(row[j]));
|
19 | return this;
|
20 | };
|
21 |
|
22 | export { tableFind, tableFindOnce };
|