mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
inital move of two ops
This commit is contained in:
parent
7ce1bf1048
commit
f491461a57
11 changed files with 244 additions and 213 deletions
46
src/core/operations/SetUnion.mjs
Normal file
46
src/core/operations/SetUnion.mjs
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue