fix(learn): update the return Object.values & solution (#40451)

This commit is contained in:
Kai-Chin Huang
2021-02-01 15:42:54 +08:00
committed by GitHub
parent 5396793179
commit 5503b54f85

View File

@ -25,7 +25,7 @@ assert(
); );
``` ```
The union of `["a", "b", "c"]` and `["c", "d"]` should return `["a", "b", "c", "d"]`. The union of a Set containing values ["a", "b", "c"] and a Set containing values ["c", "d"] should return a new Set containing values ["a", "b", "c", "d"].
```js ```js
assert( assert(
@ -67,12 +67,12 @@ class Set {
} }
// This method will return all the values in the set // This method will return all the values in the set
values() { values() {
return Object.keys(this.dictionary); return Object.values(this.dictionary);
} }
// This method will add an element to the set // This method will add an element to the set
add(element) { add(element) {
if (!this.has(element)) { if (!this.has(element)) {
this.dictionary[element] = true; this.dictionary[element] = element;
this.length++; this.length++;
return true; return true;
} }
@ -113,12 +113,12 @@ class Set {
} }
values() { values() {
return Object.keys(this.dictionary); return Object.values(this.dictionary);
} }
add(element) { add(element) {
if (!this.has(element)) { if (!this.has(element)) {
this.dictionary[element] = true; this.dictionary[element] = element;
this.length++; this.length++;
return true; return true;
} }