add tests for setOperations

This commit is contained in:
d98762625 2018-03-22 18:11:24 +00:00
parent 7d15bfe58a
commit 20e54a8ecf
3 changed files with 309 additions and 4 deletions

View file

@ -53,8 +53,8 @@ class SetOps {
}
let result = {
Union: this.runUnion,
Intersection: this.runIntersect,
"Union": this.runUnion,
"Intersection": this.runIntersect,
"Set Difference": this.runSetDifference,
"Symmetric Difference": this.runSymmetricDifference,
"Cartesian Product": this.runCartesianProduct,
@ -62,7 +62,7 @@ class SetOps {
}[operation]
.apply(null, 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") {
result = result.map(i => `${i}\n`).join("");
} else {
@ -155,12 +155,18 @@ class SetOps {
*/
runPowerSet(delimiter) {
return function(a) {
// empty array items getting picked up
a = a.filter(i => i.length);
if (!a.length) {
return [];
}
/**
*
* @param {*} dec
*/
const toBinary = (dec) => (dec >>> 0).toString(2);
const result = new Set();
const maxBinaryValue = parseInt(Number(a.map(i => "1").reduce((p, c) => p + c)), 2);
const binaries = [...Array(maxBinaryValue + 1).keys()]