DEV Community

Discussion on: Data Structures: Bidirectional Map

Collapse
 
pretaporter profile image
Maksim • Edited

Yeah, indeed keys and values required to be unique.

if (this.hasKey(key) || this.hasValue(value)) {
  throw new Error('Key or Value already exists');
}
Enter fullscreen mode Exit fullscreen mode

As you can see in current implementation, set method will throw an error in case if map already consists key or value.