Added solution to "Size of the Set" (#27508)
This commit is contained in:
@ -2,9 +2,50 @@
|
||||
title: Size of the Set
|
||||
---
|
||||
## Size of the Set
|
||||
 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/coding-interview-prep/data-structures/size-of-the-set/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
###  Problem Explanation:
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
To solve this problem, you have to write a function for the class that returns the size of the set.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
|
||||
##  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;
|
||||
}
|
||||
|
||||
 <a href='https://repl.it/repls/SereneScholarlyAnalyst' target='_blank' rel='nofollow'>Run Code</a>
|
||||
|
||||
### Code Explanation:
|
||||
|
||||
* The number of items is achieved by attaining the collection using the "values" function and getting the length attribute of it.
|
||||
|
||||
##  NOTES FOR CONTRIBUTIONS:
|
||||
|
||||
*  **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
|
||||
* Add an explanation of your solution.
|
||||
* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**. 
|
||||
|
||||
> See  <a href='http://forum.freecodecamp.com/t/algorithm-article-template/14272' target='_blank' rel='nofollow'>**`Wiki Challenge Solution Template`**</a> for reference.
|
||||
|
Reference in New Issue
Block a user