Tell us what’s happening:
I console.loged all inputs but I’m unable to pass the tests for add , clear and values methods.
I think my code is alright . Please help me figure out what I’m doing wrong.
Your code so far
var Map = function() {
this.collection = {};
// Only change code below this line
this.length = 0;
this.print = function(){
return this.collection;
}
this.add = function(key,value){
this.collection[key] = value;
this.length++
}
this.remove = function(key){
delete this.collection[key];
this.length--;
}
this.get = function(key){
return this.collection[key];
}
this.has = function(key){
if(this.collection[key]){
return true;
}
return false;
}
this.values = function(){
return Object.values(this.collection);
}
this.size = function(){
return Object.values(this.length);
}
this.clear = function(){
return (this.collection = {});
}
// Only change code above this line
};
var map = new Map();
map.add(1,3);
map.add(2,5);
map.add(3,4)
console.log(map)
console.log(map.size())
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Create a Map Data Structure
Link to the challenge: