Skip to content

Commit

Permalink
Merge pull request #191 from Jeffzholy/improvements/chapter-7-Set
Browse files Browse the repository at this point in the history
improvements: isSubsetOf function of Set
  • Loading branch information
loiane authored May 12, 2022
2 parents c0bd451 + 91887bc commit 8a39b5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
14 changes: 2 additions & 12 deletions src/js/data-structures/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 2 additions & 14 deletions src/ts/data-structures/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,8 @@ export default class Set<T> {
}

isSubsetOf(otherSet: Set<T>) {
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() {
Expand Down

0 comments on commit 8a39b5c

Please sign in to comment.