Skip to content
Advertisement

How to improve function that toggles element in map?

There is a function:

JavaScript

This function deletes element in map and adds if not exist. How can I improve it? I think this functon complecated for understanding.

Advertisement

Answer

That is definitely a complicated function.

Here’s a simpler version

JavaScript

I don’t have a typescript environment in front of me, so can’t confirm whether it passes all the typescript noise, but this will work from a javascript perspective.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement