Skip to content

Commit

Permalink
Update introduction.md (#2514)
Browse files Browse the repository at this point in the history
I think the introduction for this exercise was missing crucial information that prevented a learner from completing the task without doing external research. I've added additional information that should be sufficient to allow the learner to complete the task without any additional Googling.
  • Loading branch information
JorensM authored Jul 28, 2024
1 parent 2efaed2 commit 481dcfe
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions exercises/concept/ozans-playlist/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,31 @@ console.log(set.size);
//=> 4
```

You can provide an array as an argument when creating a set, and the array's values will become the values of the set, also removing the duplicate values.

```javascript
const array = [1, 5, 4, 1];
const set = new Set(array); // the set's values become [1, 5, 4]

console.log(set.size);
//=> 3
```

To convert a set to an array, you can use [Array.from()][mdn-array-from], which converts an iterable such as a set or a map to an array.

```javascript
const set = new Set();

set.add(1);
set.add(2);
set.add(3);
set.add(4);

const array = Array.from(set);
console.log(array);
//=> [1, 2, 3, 4]
```

[mdn-sets]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
[mdn-strict-equality]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using
[mdn-array-from]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

0 comments on commit 481dcfe

Please sign in to comment.