Skip to content

Commit 8a39b5c

Browse files
authored
Merge pull request loiane#191 from Jeffzholy/improvements/chapter-7-Set
improvements: isSubsetOf function of Set
2 parents c0bd451 + 91887bc commit 8a39b5c

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

src/js/data-structures/set.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,8 @@ export default class Set {
6363
}
6464

6565
isSubsetOf(otherSet) {
66-
if (this.size() > otherSet.size()) {
67-
return false;
68-
}
69-
let isSubset = true;
70-
this.values().every(value => {
71-
if (!otherSet.has(value)) {
72-
isSubset = false;
73-
return false;
74-
}
75-
return true;
76-
});
77-
return isSubset;
66+
const values = this.values();
67+
return values.every((value) => otherSet.has(value));
7868
}
7969

8070
isEmpty() {

src/ts/data-structures/set.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,8 @@ export default class Set<T> {
7575
}
7676

7777
isSubsetOf(otherSet: Set<T>) {
78-
if (this.size() > otherSet.size()) {
79-
return false;
80-
}
81-
82-
let isSubset = true;
83-
this.values().every(value => {
84-
if (!otherSet.has(value)) {
85-
isSubset = false;
86-
return false;
87-
}
88-
return true;
89-
});
90-
91-
return isSubset;
78+
const values = this.values();
79+
return values.every((value) => otherSet.has(value));
9280
}
9381

9482
isEmpty() {

0 commit comments

Comments
 (0)