Last active
November 25, 2015 15:14
-
-
Save bananu7/64f906584d4edfb9d75b 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
function WeakMap() { | |
this.keys = []; | |
this.values = []; | |
} | |
WeakMap.prototype.set = function set(k, v) { | |
// look for existing keys first | |
for (var kI = 0; kI < this.keys.length; kI++) { | |
if (this.keys[kI] === k) { | |
this.values[kI] = v; | |
return; | |
} | |
} | |
this.keys.push(k); | |
this.values.push(v); | |
} | |
WeakMap.prototype.get = function get(k) { | |
for (var kI = 0; kI < this.keys.length; kI++) { | |
if (this.keys[kI] === k) { | |
return this.values[kI]; | |
} | |
} | |
} | |
WeakMap.prototype.remove = function remove(k) { | |
for (var kI = 0; kI < this.keys.length; kI++) { | |
if (this.keys[kI] === k) { | |
this.keys = this.keys.splice(kI, 1); | |
this.values = this.values.splice(kI, 1); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment