DEV Community

Discussion on: JavaScript: How to implement a dictionary/map in 3mins.

Collapse
 
chinedu profile image
chinedu | ddevguys • Edited

Ok thanks for this. I will give it a shoot. But why do you think maintaining the length in the state has better performance than calling the length property directly on the object.keys?

Any tips on how you measure it?

Collapse
 
juliuskoronci profile image
Igsem

so object.keys will do a loop so we are talking about O(n) complexity while maintaining a count is O(1). So if we have 10000 elements in the map that is starting to be expensive. Also the map should be iterrable, I guess yours isnt yet :)

Thread Thread
 
chinedu profile image
chinedu | ddevguys

Thanks!