chore(curriculum): adding questions for maps and sets lecture (#57319)

This commit is contained in:
Jessica Wilkins
2024-11-26 14:04:49 -08:00
committed by GitHub
parent 24d45ae25c
commit d33f504ea7
2 changed files with 186 additions and 10 deletions

View File

@@ -14,20 +14,108 @@ Watch the video lecture and answer the questions below.
## --text--
What Is the Map Object, and How Does It Differ from WeakMaps? question?
How does a `Set` differ from a `WeakSet` when it comes to the data they both support?
## --answers--
Answer 1
A `Set` allows weakly held object references, while a `WeakSet` supports both objects and primitives.
### --feedback--
Remember that a `Set` can hold a variety of data types.
---
Answer 2
A `Set` stores any type, including primitives, while a `WeakSet` allows only weakly held object references.
---
Answer 3
A `Set` has fewer features than a `WeakSet`.
### --feedback--
Remember that a `Set` can hold a variety of data types.
---
A `Set` is exclusively for objects, while a `WeakSet` is for numbers.
### --feedback--
Remember that a `Set` can hold a variety of data types.
## --video-solution--
1
2
## --text--
How do you create a `Set` or a `WeakSet` in JavaScript?
## --answers--
By calling `Set()` or `WeakSet()` without the `new` keyword
### --feedback--
Think about what keyword needs to be included to create a `Set` or `WeakSet`.
---
By using object literals `{}`
### --feedback--
Think about what keyword needs to be included to create a `Set` or `WeakSet`.
---
By using array literals `[]`
### --feedback--
Think about what keyword needs to be included to create a `Set` or `WeakSet`.
---
By using the `Set` or `WeakSet` constructor with the `new` keyword
## --video-solution--
4
## --text--
Which methods are available to both a `Set` and a `WeakSet` in JavaScript?
## --answers--
`keys()`, `values()`, `size()`
### --feedback--
Review the end of the video where this was discussed.
---
`add()`, `delete()`, `has()`
---
`clear()`, `entries()`, `forEach()`
### --feedback--
Review the end of the video where this was discussed.
---
`set()`, `get()`, `remove()`
### --feedback--
Review the end of the video where this was discussed.
## --video-solution--
2

View File

@@ -14,20 +14,108 @@ Watch the lecture video and answer the questions below.
## --text--
What Is the Map Object, and How Does It Differ from WeakMaps? question?
Which of these differentiates a `Map` from a `WeakMap` in JavaScript?
## --answers--
Answer 1
A `Map` allows only objects as keys, while a `WeakMap` allows keys of any type.
### --feedback--
Think about the key types allowed and how the references are handled.
---
Answer 2
A `Map` has weak references to keys, while a `WeakMap` does not.
### --feedback--
Think about the key types allowed and how the references are handled.
---
Answer 3
A `Map` allows keys of any type, while a `WeakMap` only allows objects as keys.
---
A `Map` and a `WeakMap` function exactly the same.
### --feedback--
Think about the key types allowed and how the references are handled.
## --video-solution--
1
3
## --text--
Which property lets you know the number of items in a `Map`?
## --answers--
`length`
### --feedback--
Think about the property that measures the number of entries in a `Map`.
---
`count`
### --feedback--
Think about the property that measures the number of entries in a `Map`.
---
`total`
### --feedback--
Think about the property that measures the number of entries in a `Map`.
---
`size`
## --video-solution--
4
## --text--
Which method lets you add an item to a `Map` and a `WeakMap`?
## --answers--
`add()`
### --feedback--
Think about the method specifically used for adding key-value pairs to a `Map`.
---
`push()`
### --feedback--
Think about the method specifically used for adding key-value pairs to a `Map`.
---
`set()`
---
`insert()`
### --feedback--
Think about the method specifically used for adding key-value pairs to a `Map`.
## --video-solution--
3