Creating the Dictionary class
In addition to the Set
class, ECMAScript 2015 (ES6) introduced the Map
class, a fundamental data structure often referred to as a dictionary in programming. This native implementation serves as the basis for the custom dictionary class we will develop in this chapter.
The Dictionary
class we will construct draws heavily from the design principles of the JavaScript Map implementation. As we explore its structure and functionality, you will observe striking similarities to the Set
class. However, a key distinction lies in the data storage mechanism. Instead of storing only values, as in a Set, our dictionary class will accommodate key-value pairs. This modification allows us to associate unique keys with their corresponding values, thereby unlocking the full power and versatility of dictionaries as a data structure.
Our implementation will reside in the src/08-dictionary-hash/dictionary.js file. We will start by defining the Dictionary
class:
class Dictionary...