Tell us what’s happening:
why is add method and clear method wrong?
Your code so far
class Map{
constructor(){
this.collection = {};
this.length = 0
}
add(key, value){
this.collection[key] = value
this.length++
}
remove(key){
delete this.collection[key];
this.length--
}
get(key){
return this.collection[key]
}
has(key){
return this.collection[key] ? true : false
}
values(){
return Object.values(this.collection)
}
clear(){
this.collection = {};
this.length = 0
return;
}
size(){
return this.length;
}
}
let map = new Map()
map.add(1, 2)
map.add(2, 2)
console.log(map.get(1))
map.clear()
console.log(map)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
Challenge: Create a Map Data Structure
Link to the challenge: