/* * Map object, implement map function * * interface: * size () get the number of map elements &
nbsp * IsEmpty () determine if map is empty * clear () Delete all elements of map * Put (key, value) Add the element (key, value) * remove (key) to the map Delete the element of the specified key. Returns true successfully, Failure returns false * get (key) Gets the element value value of the specified key, failure returns null * Element (index) gets the element of the specified index (using Element.key,element.value to get key and value), Failure returns null * ContainsKey (key) Determines whether the map contains elements of the specified key * containsvalue (value) to determine if the map contains elements of the specified value * values ()
Gets an array of all the value in the map * keys () gets an array of all key in the map (array) * * example: * var map = new map (); * * map.put ("Key", "value"); * var val = Map.get ("key") * ...... * */ FUnction Map () { this.elements = new Array (); //Get the number of map elements this.size = function () { return this.elements.length;
} //To determine if map is empty this.isempty = function () { Return (This.elements.length < 1); } //Delete map all elements this.clear = function () { this.elements = new Array (); } //adds elements to the map (key, value) this.put = function (_key, _value) { this.elements.push ({ key: _key, value: _value  ); } //Deletes the element of the specified key. Successfully returns TRUE, Failure returns false this.remove = function (_key) { var bln = false; try{ for (i = 0; i < This.elements.length; i++) { if (This.elements[i].key = = _key) {
this.elements.splice (i, 1); return true; } }  } catch (e) { bln = false; } return bln; } //Gets the element value of the specified key, Failed to return to NULL&NBsp; this.get = function (_key) { try{ for (i = 0; i < This.elements.length; i++) { if (This.elements[i].key = = _key) { return this.elements[i].value; } } &NBSP;&NBSP;&NBSP} catch (e) { return null; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSp } // Gets the element of the specified index (using Element.key,element.value to get the key and value), and the failure returns null this.element = function (_index) { if (_index < 0 | | _index >= This.elements.length) { return null; } return this.elements[_index]; } //Determine if the map contains elements of the specified key This.containskey = function (_key) { varbln = false; try{ &Nbsp; for (i = 0; i < this.elements.length i++) {
if (This.elements[i].key = = _key) { bln = true; } }  } catch (e) { bln = false; } return bln; } //Determines whether the map contains elements of the specified value & NBsp; this.containsvalue = function (_value) {
var bln = false; try{ for (i = 0; i < this.elements.length; i++) { if (This.elements[i].value = = _value) { bln = true; } } } catch (e) { bln = False; } return bln; } //gets an array of all the value in the map (array) this.values = function () { var arr = new Array (); for (i = 0; i < this.elements.length i++) {
arr.push (This.elements[i].value); } return arr; } //gets the array (array) this.keys = function () { of all key keys in the map &Nbsp; var arr = new Array (); for (i = 0; i < this.elements.length i++) { arr.push (this.elements[i].key); } return arr; } }