
AskJS
I'm making a quick and dirty way to make dictionaries where many keys map to the same item, and instead of using a single hashable item as the key, it makes use of an array of hashable items to build the map. I don't like using tuples, but I don't think it would be valid to have an array as the key of a dictionary. I would love it if I could do that however. Is there a way to make a hashable array?
let map = MapFactory(
[
[[1,2,3], () => "1-3"],
[[4,5,6], () => "4-6"],
[[7,8,9], () => "7-9"]
]
);
console.log(map.get(1)()); // "1-3"
console.log(map.get(6)()); // "4-6"
function MapFactory(mapItems) {
const map = new Map();
for (let [keys, value] in mapItems) {
for(let key in keys) {
map.set(key, value);
}
}
return map;
}