Skip to content

Commit 481dcfe

Browse files
authoredJul 28, 2024
Update introduction.md (exercism#2514)
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.
1 parent 2efaed2 commit 481dcfe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

Diff for: ‎exercises/concept/ozans-playlist/.docs/introduction.md

+26
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,31 @@ console.log(set.size);
2525
//=> 4
2626
```
2727

28+
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.
29+
30+
```javascript
31+
const array = [1, 5, 4, 1];
32+
const set = new Set(array); // the set's values become [1, 5, 4]
33+
34+
console.log(set.size);
35+
//=> 3
36+
```
37+
38+
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.
39+
40+
```javascript
41+
const set = new Set();
42+
43+
set.add(1);
44+
set.add(2);
45+
set.add(3);
46+
set.add(4);
47+
48+
const array = Array.from(set);
49+
console.log(array);
50+
//=> [1, 2, 3, 4]
51+
```
52+
2853
[mdn-sets]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2954
[mdn-strict-equality]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using
55+
[mdn-array-from]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

0 commit comments

Comments
 (0)
Please sign in to comment.