- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Samual Sam has Published 2492 Articles
Samual Sam
1K+ Views
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. Note that a dictionary is also known as a map.The dictionary problem is a ... Read More
Samual Sam
19K+ Views
To remove an element from the dictionary, we first need to check if it exists in the dictionary.We'll use the hasKey method for that. Then we can directly delete it using the delete operator.We'll return a Boolean so that the place where we call this method can know whether the ... Read More
Samual Sam
115 Views
Sometimes when working with a dictionary, we need only the keys of the dictionary as an array for some task. We can easily get the properties of an object using Object.keys. We'll use this method to return the keys from our container object. Examplekeys() { return Object.keys(this.container); }You can test ... Read More
Samual Sam
353 Views
Here is the complete implementation of MyMap class − Exampleclass MyMap { constructor() { this.container = {}; } display() { console.log(this.container); } hasKey(key) { return key in this.container; } put(key, value) { ... Read More
Samual Sam
1K+ Views
Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access to data becomes very fast if we know the index of the desired data.Thus, it ... Read More
Samual Sam
105 Views
Whenever you want to store unique elements in a container for which the order doesn't matter and you mainly want to use it to check for membership of different objects.Sets are also useful when you want to perform operations like union, intersection, a difference like you do in mathematical sets.Let's ... Read More
Samual Sam
116 Views
The add method checks if a value already exists in the set, if not, then it adds that value to the set. We can implement it as follows − Exampleadd(val) { if (!this.has(val)) { this.container[val] = val; return true; } return false; }You can test ... Read More
Samual Sam
93 Views
The clear method is pretty straightforward. We can just reassign the container variable to a new object and the set will now be empty. This can be implemented as follows − Exampleclear() { this.container = {}; }You can test this using −Exampleconst testSet = new MySet(); testSet.add(1); testSet.add(2); testSet.add(5); ... Read More
Samual Sam
3K+ Views
The operation of adding 2 sets is known as a union. You need to add every object from one set to another while checking for duplicates. We can just use the 2 methods we already implemented to implement this method.We'll implement this function as a static function as we don’t ... Read More
Samual Sam
2K+ Views
The difference of 2 sets means the set being subtracted should have all its elements removed from the set it is being subtracted from. So we can iterate over the second set and remove all the elements present in it from the first set. Examplestatic difference(s1, s2) { if (!s1 ... Read More