Alpha
Create a new DefaultMap
with a specified default value.
Time complexity: O(n)
Space complexity: O(n)
The default value to use for missing keys
Optional
entries: null | Iterable<readonly [unknown, unknown]>const map = new DefaultMap(0);
Create a new DefaultMap
with a specified function to generate default values.
Time complexity: O(n)
Space complexity: O(n)
The function to generate default values
Optional
entries: null | Iterable<readonly [unknown, unknown]>const map = new DefaultMap(key => key.toUpperCase());
Readonly
[toReadonly
sizethe number of elements in the Map.
Static
Readonly
[species]Add an addend to the value for a given key.
The key to update the value of
The value to add to the current value
The updated value
map.add('a', 1);
true if an element in the Map existed and has been removed, or false if the element does not exist.
Divide the value for a given key by a divisor.
The key to update the value of
The value to divide the current value by
The updated value
map.divide('a', 1);
Get the value for a given key, or the default value if it's missing.
Time complexity: O(1)
Space complexity: O(1)
The key to get the value for
The value for key
, or the default value if it's missing
map.get('a');
boolean indicating whether an element with the specified key exists or not.
Multiply a multiplicand by the value for a given key.
The key to update the value of
The value to multiply the current value by
The updated value
map.multiply('a', 1);
Raise the value for a given key to an exponent.
The key to update the value of
The exponent to raise the current value to
The updated value
map.pow('a', 2);
Take the _n_th root of the value for a given key.
The key to get the _n_th root of
The root to get
The nth root of the value for key
map.root('a', 2);
Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
Square root of the value for a given key.
The key to get the square root of
The square root of the value for key
map.sqrt('a');
Subtract a subtrahend from the value for a given key.
The key to update the value of
The value to subtract from the current value
The updated value
map.subtract('a', 1);
A DefaultMap with methods for performing basic math operations that mutate the data.