MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / getHash

Function getHash

chapter07/7.12 - Hash Table/hashTable.js:40–50  ·  view source on GitHub ↗
(key, limit)

Source from the content-addressed store, hash-verified

38};
39
40var getHash = function(key, limit) {
41 if (typeof key !== 'string') {
42 throw 'error, key is not a string';
43 } else {
44 var answer = 0;
45 for (var i = 0; i < key.length; i++) {
46 answer += key[i];
47 }
48 return answer % limit;
49 }
50};
51
52var HashTable = function() {
53 this.array = [];

Callers 1

hashTable.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected