Data Structure :Can’t pass the tests for remove methods

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 => {
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:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.