javascript - Disadvantages to flattening object? -


I have some data that lends well to the undisclosed clear structure First of all I have to display nested maps , But I'm thinking that it would be more space-efficient to use only a flat structure that is indexed by the tuples with the keywords of each category.

For example, suppose that I have the data dog, cat, tree, gold, silver, first of all, suppose I had the following structure, where an arrow would have an important value pair in a map Indicates

  animal - & gt; {Bark - & gt; "Dog" purrs -> "Cat"} Plant - & gt; {Vest - & gt; "Tree"} mineral - & gt; {Golden - & gt; "Gold" Silver - & gt; "Silver"}   

But now, I'm wondering why not just

  ['animal', 'bark'] - & gt; 'Dog' ['animal', 'purrs'] - & gt; 'Cat' ['Plant', 'Roots'] - & gt; 'Tree' ['mineral', 'golden'] - & gt; 'Gold [' Minerals', 'Silver'] - & gt;  

All in one flat object? I can imagine that in this example, it is difficult to get all the minerals or all the animals - I have to do a linear search through all the keys to collect it. is there anything else?

OK, first of all, until ES6 is widely supported You will not be able to use the orange as an object key, so that you can exchange some other levels to store things properly, maybe something like this:

  {'animal ~ barks': 'dog', 'animal-purrs': 'cat', ...}   

It really makes coding with this difficult.

You will also increase your memory consumption, repeating collections, like, 'Animals'

So I think there are many attacks against it.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -