Options
All
• Public
• Public/Protected
• All

# Class MathMap<K>

A DefaultMap with methods for performing basic math operations that mutate the data.

alpha

## Constructors

• new MathMap<K>(defaultValue: number, entries?: null | Iterable<readonly [unknown, unknown]>): MathMap<K>
• new MathMap<K>(defaultValueFn: ((key: K) => number), entries?: null | Iterable<readonly [unknown, unknown]>): MathMap<K>
• Create a new `DefaultMap` with a specified default value.

Time complexity: O(n)

Space complexity: O(n)

example
``````const map = new DefaultMap(0);
``````

#### Parameters

• ##### defaultValue: number

The default value to use for missing keys

#### Returns MathMap<K>

• Create a new `DefaultMap` with a specified function to generate default values.

Time complexity: O(n)

Space complexity: O(n)

example
``````const map = new DefaultMap(key => key.toUpperCase());
``````

#### Parameters

• ##### defaultValueFn: ((key: K) => number)

The function to generate default values

• (key: K): number

## Properties

[toStringTag]: string
size: number
[species]: MapConstructor

## Methods

• [iterator](): IterableIterator<[K, number]>
• Returns an iterable of entries in the map.

#### Returns IterableIterator<[K, number]>

• Add an addend to the value for a given key.

example
``````map.add('a', 1);
``````

#### Parameters

• ##### key: K

The key to update the value of

• ##### addend: number

The value to add to the current value

#### Returns number

The updated value

• clear(): void
• #### Returns void

• delete(key: K): boolean

#### Returns boolean

• divide(key: K, divisor: number): number
• Divide the value for a given key by a divisor.

example
``````map.divide('a', 1);
``````

#### Parameters

• ##### key: K

The key to update the value of

• ##### divisor: number

The value to divide the current value by

#### Returns number

The updated value

• entries(): IterableIterator<[K, number]>
• Returns an iterable of key, value pairs for every entry in the map.

#### Returns IterableIterator<[K, number]>

• forEach(callbackfn: ((value: number, key: K, map: Map<K, number>) => void), thisArg?: any): void
• #### Parameters

• ##### callbackfn: ((value: number, key: K, map: Map<K, number>) => void)
• (value: number, key: K, map: Map<K, number>): void

#### Returns void

• get(key: K): number
• Get the value for a given key, or the default value if it's missing.

Time complexity: O(1)

Space complexity: O(1)

example
``````map.get('a');
``````

#### Parameters

• ##### key: K

The key to get the value for

#### Returns number

The value for `key`, or the default value if it's missing

• has(key: K): boolean

#### Returns boolean

• keys(): IterableIterator<K>
• Returns an iterable of keys in the map

#### Returns IterableIterator<K>

• multiply(key: K, multiplicand: number): number
• Multiply a multiplicand by the value for a given key.

example
``````map.multiply('a', 1);
``````

#### Parameters

• ##### key: K

The key to update the value of

• ##### multiplicand: number

The value to multiply the current value by

#### Returns number

The updated value

• pow(key: K, exponent: number): number
• Raise the value for a given key to an exponent.

example
``````map.pow('a', 2);
``````

#### Parameters

• ##### key: K

The key to update the value of

• ##### exponent: number

The exponent to raise the current value to

#### Returns number

The updated value

• root(key: K, root: number): number
• Take the _n_th root of the value for a given key.

example
``````map.root('a', 2);
``````

#### Parameters

• ##### key: K

The key to get the _n_th root of

• ##### root: number

The root to get

#### Returns number

The nth root of the value for `key`

• set(key: K, value: number): MathMap<K>

#### Returns MathMap<K>

• sqrt(key: K): number
• Square root of the value for a given key.

example
``````map.sqrt('a');
``````

#### Parameters

• ##### key: K

The key to get the square root of

#### Returns number

The square root of the value for `key`

• subtract(key: K, subtrahend: number): number
• Subtract a subtrahend from the value for a given key.

example
``````map.subtract('a', 1);
``````

#### Parameters

• ##### key: K

The key to update the value of

• ##### subtrahend: number

The value to subtract from the current value

#### Returns number

The updated value

• values(): IterableIterator<number>
• Returns an iterable of values in the map

#### Returns IterableIterator<number>

Generated using TypeDoc