Create a Hash Table failing one test

I am failing this test case
The remove method accepts a key as input and removes the associated key value pair.

As best I can tell from debugger I have removed the key value pair. I’ve tried this so many ways - maybe I just need a second set of eyes to see what I’m missing.

I have tried removing the entire nested object from this.collection and also tried leaving the (empty) object in place just removing key value pair.

Any help appreciated!

Your code so far

var called = 0;
var hash = (string) => {
    var hash = 0;
    for (var i = 0; i < string.length; i++) { hash += string.charCodeAt(i); }
    return hash;

var HashTable = function () {
    this.collection = {};
    // change code below this line
    this.add = function (k, v) {
        const curHash = hash(k);

        if (!this.collection[curHash]) {
            this.collection[curHash] = {};

        this.collection[curHash][k] = v;

    this.remove = function (key) {
        const curHash = hash(key);

        if (this.collection[curHash][key]) {
            delete this.collection[curHash][key];
            if (Object.entries(this.collection[curHash]).length === 0) {
                delete this.collection[curHash];
            delete this.collection[curHash]
    this.lookup = function (key) {
        const curHash = hash(key);

        if (this.collection.hasOwnProperty(curHash) && this.collection[curHash].hasOwnProperty(key)) {
            return this.collection[curHash][key];
    // 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/69.0.3497.100 Safari/537.36.

Link to the challenge:

The problem is not your remove method. The problem is your lookup method.

Look at the challenge instructions carefully for what to return in the lookup method.

The test suite is checking for a specific return value which you are not returning for the test related to checking your remove method.

1 Like

I was hoping you would chime in.

Duh! I saw it right away once you pointed me back to the lookup method. It is embarrassing how much time I spent not seeing that.

Thank you so much. Glad that is over with.