Created
April 8, 2018 17:56
-
-
Save Joopmicroop/e38f7204acc481c03062b73abeab517e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// writen but untested | |
function HashTable(obj){ | |
this.length = 0; | |
this.items = { }; | |
for(var p in obj){ | |
if(obj.hasOwnProperty(p)){ | |
this.items[p] = obj[p]; | |
this.length++; | |
} | |
} | |
return { | |
setItem: function(k,v){ | |
if(this.items.hasOwnProperty(k)) return this.items[k]; | |
this.items[k] = v; | |
}, | |
getItem: function(k){ | |
if(this.items.hasOwnProperty(k)) return this.items[k]; | |
}, | |
hasItem: function(k){ | |
return this.items.hasOwnProperty(k); | |
}, | |
removeItem: function(k){ | |
if(this.items.hasOwnProperty(k)){ | |
var prev = this.items[k]; | |
delete this.items[k]; | |
this.length--; | |
return prev; | |
} | |
}, | |
keys: function(){ | |
return Object.keys(this.items); | |
}, | |
values: function(){ | |
var vals = []; | |
for(var i in Object.keys(this.items)) vals.push(this.items[i]); | |
return vals; | |
}, | |
clear: function(){ | |
this.items = { }; | |
this.length = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment