From 4261f1d901cda448077384bc719f77b9b2a6b049 Mon Sep 17 00:00:00 2001 From: Syed Isam Hashmi Date: Sun, 2 Dec 2018 08:42:06 -0600 Subject: [PATCH] Added solution to "Size of the Set" (#27508) --- .../data-structures/size-of-the-set/index.md | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/coding-interview-prep/data-structures/size-of-the-set/index.md b/guide/english/certifications/coding-interview-prep/data-structures/size-of-the-set/index.md index c0171325bc..61a4584d35 100644 --- a/guide/english/certifications/coding-interview-prep/data-structures/size-of-the-set/index.md +++ b/guide/english/certifications/coding-interview-prep/data-structures/size-of-the-set/index.md @@ -2,9 +2,50 @@ title: Size of the Set --- ## Size of the Set +![:triangular_flag_on_post:](https://forum.freecodecamp.com/images/emoji/emoji_one/triangular_flag_on_post.png?v=3 ":triangular_flag_on_post:") Remember to use **`Read-Search-Ask`** if you get stuck. Try to pair program ![:busts_in_silhouette:](https://forum.freecodecamp.com/images/emoji/emoji_one/busts_in_silhouette.png?v=3 ":busts_in_silhouette:") and write your own code ![:pencil:](https://forum.freecodecamp.com/images/emoji/emoji_one/pencil.png?v=3 ":pencil:") -This is a stub. Help our community expand it. +### ![:checkered_flag:](https://forum.freecodecamp.com/images/emoji/emoji_one/checkered_flag.png?v=3 ":checkered_flag:") Problem Explanation: -This quick style guide will help ensure your pull request gets accepted. +To solve this problem, you have to write a function for the class that returns the size of the set. - + +## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1 + +Create a size function in the Set class. + +> _try to solve the problem now_ + +## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 2 + +Use the length attribute on the values of the Set. + +> _try to solve the problem now_ + + + +## Spoiler Alert! + +![warning sign](//discourse-user-assets.s3.amazonaws.com/original/2X/2/2d6c412a50797771301e7ceabd554cef4edcd74d.gif) + +**Solution ahead!** + +## ![:beginner:](https://forum.freecodecamp.com/images/emoji/emoji_one/beginner.png?v=3 ":beginner:") Basic Code Solution: + + this.size = function() + { + return this.values().length; + } + +![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":rocket:") Run Code + +### Code Explanation: + +* The number of items is achieved by attaining the collection using the "values" function and getting the length attribute of it. + +## ![:clipboard:](https://forum.freecodecamp.com/images/emoji/emoji_one/clipboard.png?v=3 ":clipboard:") NOTES FOR CONTRIBUTIONS: + +* ![:warning:](https://forum.freecodecamp.com/images/emoji/emoji_one/warning.png?v=3 ":warning:") **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**. ![:traffic_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/traffic_light.png?v=3 ":traffic_light:") + +> See ![:point_right:](https://forum.freecodecamp.com/images/emoji/emoji_one/point_right.png?v=3 ":point_right:") **`Wiki Challenge Solution Template`** for reference.