Merge map values

Mohan.Radhakrishnan at Mohan.Radhakrishnan at
Tue Apr 28 08:52:59 UTC 2015


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().
        collect(TreeMap::new, (m, c) -> m.merge((char) c, 1, Integer::sum), Map::putAll);

What could be the es6 equivalent ?

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: <>

More information about the es-discuss mailing list