CyberChef/src/core/operations/SetUnion.mjs

47 lines
859 B
JavaScript
Raw Normal View History

2018-04-04 18:37:19 +02:00
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;