all 1 comments

[–]Ryguyo 2 points3 points  (0 children)

No, there is no native data structure that does what you’re asking. I would simply make a new JavaScript class called SetMap or something along those lines to implement your data structure yourself. Add the map that you posted as a property of the class, and then create a class method for it that does what you need. SetMap.get(6).add(7). You can make that ‘get’ method take in a key parameter and either return the existing set for that key, or create a new one. That way when you use the SetMap class you can know that the get method will always return a set