diff --git a/Data Structures/map.js b/Data Structures/map.js new file mode 100644 index 0000000..c1ebcbd --- /dev/null +++ b/Data Structures/map.js @@ -0,0 +1,34 @@ +// https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-map-data-structure + +var Map = function () { + this.collection = {}; + // Only change code below this line + this.add = (k, v) => { + this.collection[k] = v; + }; + + this.remove = (k) => { + delete this.collection[k]; + }; + + this.get = (k) => { + return this.collection[k]; + }; + + this.has = (k) => { + return this.collection[k] !== undefined; + }; + + this.values = () => { + return Object.values(this.collection); + }; + + this.size = () => { + return Object.keys(this.collection).length; + }; + + this.clear = () => { + this.collection = {}; + }; + // Only change code above this line +};