Skip to content

Commit 17fb236

Browse files
committed
Simplify contains method for set
1 parent 21a0645 commit 17fb236

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

data-structures-in-javascript/set.es6.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ class Set {
2020
}
2121

2222
contains(value) {
23-
if(~this.values.indexOf(value)) {
24-
return true;
25-
} else {
26-
return false;
27-
}
23+
return this.values.indexOf(value) !== -1;
2824
}
2925

3026
union(set) {

data-structures-in-javascript/set.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ Set.prototype.remove = function(value) {
1717
}
1818
};
1919
Set.prototype.contains = function(value) {
20-
if(~this.values.indexOf(value)) {
21-
return true;
22-
} else {
23-
return false;
24-
}
20+
return this.values.indexOf(value) !== -1;
2521
};
2622
Set.prototype.union = function(set) {
2723
var newSet = new Set();

0 commit comments

Comments
 (0)