MapInterface

MapInterface

Map Interface

Methods

clear() → {undefined}

Clears the map of all k,v pairs
Returns:
Type
undefined

contains(key) → {boolean}

Reports whether the Map contains the given key
Example
map.contains("empty"); // return false
Parameters:
Name Type Description
key * The key to lookup
Returns:
True if @param key is found and false otherwise
Type
boolean

getVal(key) → {*}

Retrieves the value mapped to by the given key
Example
map.put(99, "problems");
map.getVal(99); // returns "problems"
Parameters:
Name Type Description
key * The key to lookup
Returns:
The value associated with @param key
Type
*

keys() → {Array}

Returns all of the keys in the Map
Example
map.put(1, "b");
map.put(2, "c");
map.put(3, "d");
map.keys() // returns [1, 2, 3] permutation (order may
or may not be guarenteed)
Returns:
An array of keys
Type
Array

put(key, value) → {Map}

Inserts the given key and value into the Map
Example
map.put("ed", "jones");
// ed maps to jones
map.put("ed", "james");
// now same ed maps to james and not jones
Parameters:
Name Type Description
key * The key
value * The value mapped to by @param key
Returns:
The instance that this method was called
Type
Map

remove(key) → {boolean}

Removes the given key and its associated value from the Map
Example
map.put(99, "problems");
map.remove(88); // returns false
map.remove(99); // returns true
Parameters:
Name Type Description
key * The key to lookup
Returns:
True if the key and it's value were removed and false otherwise
Type
boolean

size() → {number}

Returns number of elements in the Map
Example
map.put(99, "problems");
map.size() // 1
Returns:
The number of insertions
Type
number

values() → {Array}

Returns all of the values in the Map
Example
map.put(1, "b");
map.put(2, "c");
map.put(3, "d");
map.values() // returns ["c", "b", "d"] permutation
Returns:
An array of values
Type
Array