inital move of two ops

This commit is contained in:
d98762625 2018-04-04 17:37:19 +01:00
parent 7ce1bf1048
commit f491461a57
11 changed files with 244 additions and 213 deletions

View file

@ -0,0 +1,46 @@
import SetOp from "./SetOps";
/**
*
*/
class SetUnion extends SetOp {
/**
*
*/
constructor() {
super();
this.setOp = this.runUnion;
this.name = "Set Union";
this.description = "Get the union of two sets";
}
/**
* Get the union of the two sets.
*
* @param {Object[]} a
* @param {Object[]} b
* @returns {Object[]}
*/
runUnion(a, b) {
const result = {};
/**
* Only add non-existing items
* @param {Object} hash
*/
const addUnique = (hash) => (item) => {
if (!hash[item]) {
hash[item] = true;
}
};
a.map(addUnique(result));
b.map(addUnique(result));
return Object.keys(result).join(this.itemDelimiter);
}
}
export default SetUnion;