Data Structures: Create a Map Data Structure
This commit is contained in:
parent
c5b1dc2825
commit
e0c1357fe8
34
Data Structures/map.js
Normal file
34
Data Structures/map.js
Normal file
@ -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
|
||||
};
|
Loading…
Reference in New Issue
Block a user