Merge map values

Mohan.Radhakrishnan at cognizant.com Mohan.Radhakrishnan at cognizant.com
Tue Apr 28 10:02:00 UTC 2015


It could be something like this. But if this is done internall then we don't need code to explicitly manipulate the Map.

let m = new Map();
m.set("x",1);
//set other keys

//for (let value of m.entries()){

    //if (Object.keys(m).every((key) => m[key] == value[key])){
        //Merge
    //}
//}
}

Thanks,
Mohan

From: Radhakrishnan, Mohan (Cognizant)
Sent: Tuesday, April 28, 2015 2:23 PM
To: 'es-discuss at mozilla.org'
Subject: Merge map values

Hi,

I am using ES6 by transpiling. The features remind me of Java lambdas.

If I have a string 'mainn' then my map should contain this.

[a=1, i=1, m=1, n=2]

Java : Example. I may not need the TreeMap here.

String s  = "__mainn__".replaceAll("[^a-z\\s]", "");


final Map<Character, Integer> count = s.chars().
        map(Character::toLowerCase).
        collect(TreeMap::new, (m, c) -> m.merge((char) c, 1, Integer::sum), Map::putAll);

What could be the es6 equivalent ?

Thanks,
Mohan
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150428/35579c60/attachment.html>


More information about the es-discuss mailing list