set - nodef/extra-bimap GitHub Wiki

Adds or updates an element with a specified key and a value to map.

BiMap.prototype.set(key, value);
// key:   key of the element to add
// value: value of the element to add
// --> map (this)
const BiMap = require('extra-bimap');

var m = new BiMap();
// BiMap [Map] {}

m.set(1, 'a');
// BiMap [Map] { 1 => 'a' }

m.set(2, 'b');
// BiMap [Map] { 1 => 'a', 2 => 'b' }

m.set(2, 'a');
// Error: BiMap pair is not unique

m.set(2, 'c');
// BiMap [Map] { 1 => 'a', 2 => 'c' }