javascript - Map using tuples or objects -


I am trying to use new (ES6) objects to represent a map between properties and value I am

I have the same form of objects:

  {key1: value1_1, key2: value2_1}, ..... {key1: value1_N, key2: value2_N} < / Code> 

I want to group them by both their key1 and key2 values. For example, I want to x and y

  lower than [{x: 3, y: 5, z: 3} The group may be able to group, {x: 3, y: 4, z: 4} {x: 3, y: 4, z: 7} {x: 3, y: 1, z: 1} {x : 3, Y: 5, Z: 4}]  

and get a map with:

  {x: 3, y: 5} = = & Gt; {X: 3, y: 5, z: 3}, {x: 3, y: 5, z: 4} {x: 3, y: 4} ==> {X: 3, y: 4, z: 4}, {x: 3, y: 4, z: 7} {x: 3, y: 1} == & gt; {X: 3, y: 1, z: 1}  

In Python, I use Tupale as a dictionary key. ES6 permits arbitrary objects in the form of map keys, but use the standard parallel algorithm ( === ), so the object is the equivalent of the context of only I can tell.

How can I do this like the group using ES6 maps? Alternatively, using a simple JS objects is a solution if I have a great way to ignore.

I do not want to use an external archive library - but if I am interested in learning a better solution using one, also about it.

OK, I have just raised this issue and answered me to Mozilla:

< Ol>
  • This is a problem with ES6 maps.
  • Instead of the object, the solution for the arc will be as ES7.
  • People were previously considered to specify .equals and .hashCode , but it was rejected in favor of price object (For good reasons in my opinion).
  • The only solution is to roll your archive now.
  • A basic collection (concept, not used in the production code) was presented on the ESDiscuss thread by Bradley and something like this might appear:

     < Code> function hash map (hash) {var map = new map; Var _set = map.set; Var _get = map.get; Var _has = map.has; Var _delete = map.delete; Map.set = function (k, v) {return_set.call (map, hash (k), v); } Map.get = function (k) {return _get.call (map, hash (k)); } Map.has = function (k) {back _has.call (map, hash (k)); } Map.delete = function (k) {return _delete.call (map, hash (k)); } Return map; } Function TupleMap () {new hashmem (function)} {var keys = Object.keys (Tupal). SOURT (); Return bracket. Map (function (TUPK) {// hash json stringing returns based on json.stringify (Tupelleke) + Jason.Stringuev (Tupal [Tupelek]);}). ('\ N'); Return;}); }  

    A better solution is to use something like that which allows for specifications of hash / specifications

    You can view API docs.


    Comments

    Popular posts from this blog

    ios - How do I use CFArrayRef in Swift? -

    eclipse plugin - Run java code error: Workspace is closed -

    c - Error on building source code in VC 6 -