From 4464d54b9a4cfeadb35babc82078b2bbba8122fe Mon Sep 17 00:00:00 2001 From: Jorens Merenjanu Date: Sat, 27 Jul 2024 12:32:46 +0300 Subject: [PATCH] Update introduction.md 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. --- .../ozans-playlist/.docs/introduction.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/exercises/concept/ozans-playlist/.docs/introduction.md b/exercises/concept/ozans-playlist/.docs/introduction.md index e7f8a3c2d8..2a5c914459 100644 --- a/exercises/concept/ozans-playlist/.docs/introduction.md +++ b/exercises/concept/ozans-playlist/.docs/introduction.md @@ -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