how hash functions work in javascript

3 basic methods:
1-method put(key, value);
2-method remove(key);
3-method get(key);
here is basic code:
function HashTable() {
let table = [];

let looselooseHash = function (key) {
let hash = 0;
for (let i = 0; i < key.length; i++) {
hash += key.charCodeAt(i);
}

return hash % 37;
Enter fullscreen mode
Exit fullscreen mode

};

this.put = function (key, value) {
let position = looselooseHash(key);
console.log(position + ” – ” + key);
table[position] = value;
};
}

let table = new HashTable();
table.put(“nurbekjon”, “nur.softwaredev”);
table.put(“nurbekjo”, “[email protected]“);
table.put(“azamat”, “[email protected]“);


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Net offer ssd storage ? get a host. The rise of decentralized databases : a new era of data storage. Android app development.