From the course: JavaScript: Maps and Sets
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Sets 2 - JavaScript Tutorial
From the course: JavaScript: Maps and Sets
Solution: Sets 2
(upbeat music) - [Instructor] For this challenge, we're given an array of guesses. We're also given a winning number, and we need to determine, is that winning number in our guesses set that we're going to create? So the first thing that we want to do is set up our set. So very similar to the challenge that you just completed. We're going to go ahead and create a new variable, and I'll call that guessesSet, and we'll instantiate a new set here. Then, very similar to last time, I'm going to loop over this guesses array, and for each value, I'm going to add it to our set. As I mentioned before, there could be a number of different ways that you decide to do this. I'm going to show you one way that's going to give you some practice with array methods as well. If you choose to do it another way, that's totally fine, as long as you get the correct answer or solution and using a set, then you've done what you're supposed to do. So let's go ahead and we'll reference our array of guesses, and…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
The Set object defined57s
-
(Locked)
Add values to your set3m 17s
-
(Locked)
Does Set have your value?3m 9s
-
Get your set size2m 2s
-
(Locked)
Delete and clear values in your set2m 46s
-
(Locked)
Iterate over values in a set2m 45s
-
(Locked)
Iterate over a set with entries2m 25s
-
(Locked)
Iterate over your set with forEach2m 29s
-
(Locked)
Solution: Sets 12m 8s
-
(Locked)
Solution: Sets 22m 35s
-
-
-