diff --git a/src/js/data-structures/set.js b/src/js/data-structures/set.js index 0dc29a0c..996316ac 100644 --- a/src/js/data-structures/set.js +++ b/src/js/data-structures/set.js @@ -63,18 +63,8 @@ export default class Set { } isSubsetOf(otherSet) { - if (this.size() > otherSet.size()) { - return false; - } - let isSubset = true; - this.values().every(value => { - if (!otherSet.has(value)) { - isSubset = false; - return false; - } - return true; - }); - return isSubset; + const values = this.values(); + return values.every((value) => otherSet.has(value)); } isEmpty() { diff --git a/src/ts/data-structures/set.ts b/src/ts/data-structures/set.ts index c67faf75..a6d37373 100644 --- a/src/ts/data-structures/set.ts +++ b/src/ts/data-structures/set.ts @@ -75,20 +75,8 @@ export default class Set { } isSubsetOf(otherSet: Set) { - if (this.size() > otherSet.size()) { - return false; - } - - let isSubset = true; - this.values().every(value => { - if (!otherSet.has(value)) { - isSubset = false; - return false; - } - return true; - }); - - return isSubset; + const values = this.values(); + return values.every((value) => otherSet.has(value)); } isEmpty() {