EXCERSICE :HashMaps
1 **Can’t pass the tests for remove methods even after copying the solution **
I coded this first myself but couldn’t pass the tests ,and after taking the hints or even pasting the official/FCC solution I am not able to pass the tests made for hashes remove method
**Your code so far**
let called = 0;
let hash = string => {
called++;
var hashed = 0;
for (var i = 0; i < string.length; i++) {
hashed += string.charCodeAt(i);
}
return hashed;
};
let HashTable = function() {
this.collection = {};
// Only change code below this line
this.add = (key, value) => {
const hashedKey = hash(key);
this.collection[hashedKey] = this.collection[hashedKey] || {};
this.collection[hashedKey][key] = value;
}
this.lookup = (key) => {
const hashedKey = hash(key);
return this.collection[hashedKey][key];
}
this.remove = (key) => {
const hashedKey = hash(key);
delete this.collection[hashedKey][key];
if (!!Object.keys(this.collection[hashedKey]).length)
delete this.collection[hashedKey];
}
// Only change code above this line
};
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36
Challenge: Create a Hash Table
Link to the challenge: