JavaScript Calling a Method on a Linked List inside of Javascript implementation of a Hash Table

I'm working on creating a Hash Table in Javascript to better understand the data structure. I implemented it with a Linked List at each table position to deal with conflicts.

The problem is that I cannot call .add on this.storage[index], as it is undefined. When I log this.storage[index] I see my head nodes in my linked list and the methods that I need. So I'm not sure what the problem is.

var Node = function(key, value) {
  this.key = key;
  this.value = value;
  this.next = null;
};

var LinkedList = function() {
  this.head = new Node('head');
  this.add = function(key, value) {
    var node = new Node(key, value);
    var curNode = this.head;
    while (curNode.next !== null) {
      curNode = curNode.next;
    }
    curNode.next = node;
  };
  this.find = function(key) {
    var curNode = this.head;
    while (curNode.key !== key && curNode.next !== null) {
      curNode = curNode.next;
    }
    return curNode.value;
  };
};

var HashTable = function(max) {
  this.max = max;
  this.storage = [];
  for (var i = 0; i < max; ++i) {
    this.storage[i] = new LinkedList();
  }
  this.hash = function(key) {
    var sum = 0;
    for (var i = 0; i < key.length; ++i) {
      sum += key[i].charCodeAt() - 97;
    }
    return sum % this.max;
  };
  this.addValue = function(key, value) {
    var index = this.hash(key);
    this.storage[index].add(key, value);
  };
  this.getValue = function(key) {
    var index = this.hash(key);
    return this.storage[index].find(key);
  };
};

var hash = new HashTable(5);
hash.addValue("I");
hash.addValue("would");
hash.addValue("like");
hash.addValue("coffee");
hash.getValue('I');
Answer:1

I'm pretty new with angular and I've read a lot of threads here and googled this topic but I cannot get a clear answer. What I'm trying to do is pass a value that is not set until the user makes a ...

I'm pretty new with angular and I've read a lot of threads here and googled this topic but I cannot get a clear answer. What I'm trying to do is pass a value that is not set until the user makes a ...

Consider sample html code: <head> .... <script src="/js/MyClass.js"></script> <script src="/js/extend.js"></script> <script> $(document)....

Consider sample html code: <head> .... <script src="/js/MyClass.js"></script> <script src="/js/extend.js"></script> <script> $(document)....

  1. method overloading javascript
  2. method overload js

In the following code, I have two Book Collections. One collection has "Moby Dick," while the other collection has "The Firm." However, when I look at the second collection, it also has Moby Dick. How ...

In the following code, I have two Book Collections. One collection has "Moby Dick," while the other collection has "The Firm." However, when I look at the second collection, it also has Moby Dick. How ...

Check here javascript:Function("alert('this is ok')")(); same as new Function("alert('this is ok')")(); What the syntax called ? Any reference ? EDIT Sorry, my fault,it's only a label,and it's ...

Check here javascript:Function("alert('this is ok')")(); same as new Function("alert('this is ok')")(); What the syntax called ? Any reference ? EDIT Sorry, my fault,it's only a label,and it's ...

  1. what does javascript do
  2. what does javascript mean
  3. what does javascript look like
  4. what does javascript void mean
  5. what does javascript need to work on a website
  6. what does javascript compile to
  7. what does javascript stand for
  8. what does javascript void(0)
  9. what does javascript code look like
  10. what does javascript do for a website
  11. what does javascript do in html
  12. what does javascript run on
  13. what does javascript error mean
  14. what does javascript eval do
  15. what does javascript map return
  16. what does javascript developer do
  17. what does javascript require do
  18. what does javascript trim do
  19. what does javascript await do
  20. what does javascript have to do with java