Skip to content

Commit 44c54ca

Browse files
committed
chapter 06: [Sets]
1 parent 851e8bb commit 44c54ca

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/js/data-structures/set.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ export default class Set {
22
constructor() {
33
this.items = {};
44
}
5-
add(value) {
6-
if (!this.has(value)) {
7-
this.items[value] = value;
5+
add(element) {
6+
if (!this.has(element)) {
7+
this.items[element] = element;
88
return true;
99
}
1010
return false;
1111
}
12-
delete(value) {
13-
if (this.has(value)) {
14-
delete this.items[value];
12+
delete(element) {
13+
if (this.has(element)) {
14+
delete this.items[element];
1515
return true;
1616
}
1717
return false;
1818
}
19-
has(value) {
20-
return Object.prototype.hasOwnProperty.call(this.items, value);
19+
has(element) {
20+
return Object.prototype.hasOwnProperty.call(this.items, element);
2121
}
2222
values() {
2323
return Object.values(this.items);

src/ts/data-structures/set.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ export default class Set<T> {
55
this.items = {};
66
}
77

8-
add(value: T) {
9-
if (!this.has(value)) {
10-
this.items[value] = value;
8+
add(element: T) {
9+
if (!this.has(element)) {
10+
this.items[element] = element;
1111
return true;
1212
}
1313
return false;
1414
}
1515

16-
delete(value: T) {
17-
if (this.has(value)) {
18-
delete this.items[value];
16+
delete(element: T) {
17+
if (this.has(element)) {
18+
delete this.items[element];
1919
return true;
2020
}
2121
return false;
2222
}
2323

24-
has(value: T) {
25-
// return this.items.hasOwnProperty(value);
26-
return Object.prototype.hasOwnProperty.call(this.items, value);
24+
has(element: T) {
25+
// return this.items.hasOwnProperty(element);
26+
return Object.prototype.hasOwnProperty.call(this.items, element);
2727
}
2828

2929
values(): T[] {

0 commit comments

Comments
 (0)