Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created July 25, 2020 12:06
Show Gist options
  • Save deleteman/f58f263cb5f099ff47b93a8831930578 to your computer and use it in GitHub Desktop.
Save deleteman/f58f263cb5f099ff47b93a8831930578 to your computer and use it in GitHub Desktop.
class HashMap {
constructor() {
this.map = {}
}
hash(k) {
return k % 10
}
add(key, value) {
let k = this.hash(key)
if(!this.map[k]) {
this.map[k] = []
}
this.map[k].push(value)
}
get(key) {
let k = this.hash(key)
return this.map[k]
}
}
let h = new HashMap()
h.add(10, "hello")
h.add(100001, "world")
h.add(1, "this is a string")
console.log(h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment