2.5 KiB
2.5 KiB
title
title |
---|
Size of the Set |
Size of the Set
Remember to use
Read-Search-Ask
if you get stuck. Try to pair program and write your own code
Problem Explanation:
To solve this problem, you have to write a function for the class that returns the size of the set.
Hint: 1
Create a size function in the Set class.
try to solve the problem now
Hint: 2
Use the length attribute on the values of the Set.
try to solve the problem now
Spoiler Alert!
Solution ahead!
Basic Code Solution:
this.size = function()
{
return this.values().length;
}
Code Explanation:
- The number of items is achieved by attaining the collection using the "values" function and getting the length attribute of it.