feat(curriculum): add interactive examples to JS Maps and Sets Review (#65313)

Co-authored-by: Jeevankumar-S <jeevenkumar2003@email.com>
This commit is contained in:
Jeevankumar S
2026-01-20 16:34:08 +05:30
committed by GitHub
parent 1fc9a057f4
commit cdb1610682

View File

@@ -5,7 +5,7 @@ challengeType: 31
dashedName: review-javascript-maps-and-sets
---
# --description--
# --interactive--
## Sets in JavaScript
@@ -13,11 +13,15 @@ dashedName: review-javascript-maps-and-sets
- Sets ensure that each value in it appears only once, making it useful for eliminating duplicates from an array or handling collections of distinct values.
- You can create a `Set` using the `Set()` constructor:
:::interactive_editor
```js
const set = new Set([1, 2, 3, 4, 5]);
console.log(set); // Set { 1, 2, 3, 4, 5 }
```
:::
- Sets can be manipulated using these methods:
- `add()`: Adds a new element to the `Set`.
@@ -43,6 +47,8 @@ console.log(set); // Set { 1, 2, 3, 4, 5 }
- A `Map` provides better performance over the standard object when it comes to frequent addition and removals of key-value pairs.
- You can create a `Map` using the `Map()` constructor:
:::interactive_editor
```js
const map = new Map([
['flower', 'rose'],
@@ -52,6 +58,8 @@ const map = new Map([
console.log(map); // Map(3) { 'flower' => 'rose', 'fruit' => 'apple', 'vegetable' => 'carrot' }
```
:::
- Maps can be manipulated using these methods:
- `set()`: Adds a new key-value pair to the `Map`.