Skip to content

Instantly share code, notes, and snippets.

@ekaitz-zarraga
Created March 3, 2023 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekaitz-zarraga/abba93e24f35e656361f353d229a20b7 to your computer and use it in GitHub Desktop.
Save ekaitz-zarraga/abba93e24f35e656361f353d229a20b7 to your computer and use it in GitHub Desktop.
a JavaScript Map that compares keys by equality and not by reference LUL
function MyMap(){
this.map = new Map();
}
MyMap.prototype.set= function(k,v){
this.map.set(JSON.stringify(k), v);
}
MyMap.prototype.get= function(k){
return this.map.get(JSON.stringify(k));
}
MyMap.prototype.has= function (k){
this.map.has(JSON.stringify(k));
}
MyMap.prototype.forEach= function(f){
this.map.forEach((v,k,map)=>{
f(v, JSON.parse(k), map);
});
}
let m = new MyMap()
m.set([0,1],89);
console.log( m.get([0,1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment