add comments

This commit is contained in:
d98762625 2018-03-25 16:42:33 +01:00
parent 20e54a8ecf
commit 2c68be3193
1 changed files with 39 additions and 21 deletions

View File

@ -1,11 +1,18 @@
import Utils from "../Utils.js"; import Utils from "../Utils.js";
/** /**
* Set operations.
* *
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2018
* @license APache-2.0
*
* @namespace
*/ */
class SetOps { class SetOps {
/** /**
* * Set default options for operation
*/ */
constructor() { constructor() {
this._sampleDelimiter = "\\n\\n"; this._sampleDelimiter = "\\n\\n";
@ -14,21 +21,24 @@ class SetOps {
} }
/** /**
* * Get operations array
* @returns {String[]}
*/ */
get OPERATION() { get OPERATION() {
return this._operation; return this._operation;
} }
/** /**
* * Get sample delimiter
* @returns {String}
*/ */
get SAMPLE_DELIMITER() { get SAMPLE_DELIMITER() {
return this._sampleDelimiter; return this._sampleDelimiter;
} }
/** /**
* * Get item delimiter
* @returns {String}
*/ */
get ITEM_DELIMITER() { get ITEM_DELIMITER() {
return this._itemDelimiter; return this._itemDelimiter;
@ -36,9 +46,11 @@ class SetOps {
/** /**
* Run the configured set operation.
* *
* @param {*} input * @param {String} input
* @param {*} args * @param {String[]} args
* @returns {html}
*/ */
runSetOperation(input, args) { runSetOperation(input, args) {
const [sampleDelim, itemDelimiter, operation] = args; const [sampleDelim, itemDelimiter, operation] = args;
@ -73,17 +85,19 @@ class SetOps {
} }
/** /**
* Get the union of the two sets.
* *
* @param {*} a * @param {Object[]} a
* @param {*} a * @param {Object[]} b
* @returns {Object[]}
*/ */
runUnion(a, b) { runUnion(a, b) {
const result = {}; const result = {};
/** /**
* * Only add non-existing items
* @param {*} r * @param {Object} hash
*/ */
const addUnique = (hash) => (item) => { const addUnique = (hash) => (item) => {
if (!hash[item]) { if (!hash[item]) {
@ -98,9 +112,10 @@ class SetOps {
} }
/** /**
* * Get the intersection of the two sets.
* @param {*} a * @param {Object[]} a
* @param {*} b * @param {Object[]} b
* @returns {Object[]}
*/ */
runIntersect(a, b) { runIntersect(a, b) {
return a.filter((item) => { return a.filter((item) => {
@ -109,9 +124,10 @@ class SetOps {
} }
/** /**
* * Get elements in set a that are not in set b
* @param {*} a * @param {Object[]} a
* @param {*} b * @param {Object[]} b
* @returns {Object[]}
*/ */
runSetDifference(a, b) { runSetDifference(a, b) {
return a.filter((item) => { return a.filter((item) => {
@ -120,14 +136,16 @@ class SetOps {
} }
/** /**
* * Get elements of each set that aren't in the other set.
* @param {*} a * @param {Object[]} a
* @param {*} b * @param {Object[]} b
* @return {Object}
*/ */
runSymmetricDifference(a, b) { runSymmetricDifference(a, b) {
/** /**
* * One-way difference function, formatted for mapping.
* @param {*} refArray * @param {Object[]} refArray
*/ */
const getDifference = (refArray) => (item) => { const getDifference = (refArray) => (item) => {
return refArray.indexOf(item) === -1; return refArray.indexOf(item) === -1;