From b2fa8896ba0e66884274a6734a4fa22abb5ecc18 Mon Sep 17 00:00:00 2001 From: Syed Isam Hashmi Date: Thu, 21 Mar 2019 11:03:36 -0500 Subject: [PATCH] Added solution for "Create and Add to Sets in ES6" (#27554) * Added solution for "Create and Add to Sets in ES6" * add full solution * Remove notes --- .../create-and-add-to-sets-in-es6/index.md | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/coding-interview-prep/data-structures/create-and-add-to-sets-in-es6/index.md b/guide/english/certifications/coding-interview-prep/data-structures/create-and-add-to-sets-in-es6/index.md index 45f659bb23..318d15cce2 100644 --- a/guide/english/certifications/coding-interview-prep/data-structures/create-and-add-to-sets-in-es6/index.md +++ b/guide/english/certifications/coding-interview-prep/data-structures/create-and-add-to-sets-in-es6/index.md @@ -3,8 +3,58 @@ title: Create and Add to Sets in ES6 --- ## Create and Add to Sets in ES6 -This is a stub. Help our community expand it. -This quick style guide will help ensure your pull request gets accepted. +![: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:") - +### ![:checkered_flag:](https://forum.freecodecamp.com/images/emoji/emoji_one/checkered_flag.png?v=3 ":checkered_flag:") Problem Explanation: + +To solve this problem, you have to add an array of items to the set. + + +## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1 + +Use the add function to add an array of strings to the set. + +> _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: + +```js +function checkSet() { + var set = new Set([1, 2, 3, 3, 2, 1, 2, 3, 1]); + set.add("Taco"); + set.add("Cat"); + set.add("Awesome"); + console.log(Array.from(set)); + return set; +} + +checkSet(); +``` + +![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":rocket:") Run Code + +### Code Explanation: + +* Creating a set object as shown in pre-written code will create the set without duplicate objects. +* Therefore, by using the add function, we can add items to the set and they will not be duplicated, and will still be represented in the array. + +## ![: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:")