Hashing

function createKey(word) {    value = 0
for(letter of word) {
value += word.charCodeAt(0)
}
return value
}
function createTable(arr) {
let table = [...Array(Math.floor(arr.length * 1.3))].map(() => false)
for(word of arr) {
key = createKey(word)
while(table[key % Math.floor(arr.length * 1.3)] != word) {
if(!table[key % Math.floor(arr.length * 1.3)]) {
table[key % Math.floor(arr.length * 1.3)] = word
} else {
key += 1
}
}
}
return table
}
function createTable(arr) {
let table = [...Array(10].map(() => false)
for(word of arr) {
key = createKey(word) % 10
spot = table[key]
if(!spot) {
table[key] = Node.new()
table[key].data = word
} else {
while(spot.next){
spot = spot.next
}
spot.next = Node.new()
spot.next.data = word
}
}
return table
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store