35 lines
688 B
JavaScript
35 lines
688 B
JavaScript
|
// 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
|
||
|
};
|