reuse difference function for symmetric difference
This commit is contained in:
parent
2c68be3193
commit
208cb05c74
@ -72,7 +72,7 @@ class SetOps {
|
|||||||
"Cartesian Product": this.runCartesianProduct,
|
"Cartesian Product": this.runCartesianProduct,
|
||||||
"Power Set": this.runPowerSet(itemDelimiter),
|
"Power Set": this.runPowerSet(itemDelimiter),
|
||||||
}[operation]
|
}[operation]
|
||||||
.apply(null, sets.map(s => s.split(itemDelimiter)));
|
.apply(this, sets.map(s => s.split(itemDelimiter)));
|
||||||
|
|
||||||
// Formatting issues due to the nested characteristics of power set.
|
// Formatting issues due to the nested characteristics of power set.
|
||||||
if (operation === "Power Set") {
|
if (operation === "Power Set") {
|
||||||
@ -142,18 +142,8 @@ class SetOps {
|
|||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
runSymmetricDifference(a, b) {
|
runSymmetricDifference(a, b) {
|
||||||
|
return this.runSetDifference(a,b)
|
||||||
/**
|
.concat(this.runSetDifference(b, a));
|
||||||
* One-way difference function, formatted for mapping.
|
|
||||||
* @param {Object[]} refArray
|
|
||||||
*/
|
|
||||||
const getDifference = (refArray) => (item) => {
|
|
||||||
return refArray.indexOf(item) === -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
return a
|
|
||||||
.filter(getDifference(b))
|
|
||||||
.concat(b.filter(getDifference(a)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user