mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
47 lines
859 B
JavaScript
47 lines
859 B
JavaScript
|
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;
|