The best I can come up with is a totally different, less functional approach:
```js
const s = 'mainn';
let map = new Map();
for (let ch of s) {
ch = ch.toLowerCase();
const prevCount = map.get(ch) || 0;
map.set(ch, prevCount+1);
}
```
> On 28 Apr 2015, at 10:52 , <[email protected]>
> <[email protected]> wrote:
>
> 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.
> _______________________________________________
> es-discuss mailing list
> [email protected] <mailto:[email protected]>
> https://mail.mozilla.org/listinfo/es-discuss
> <https://mail.mozilla.org/listinfo/es-discuss>
--
Dr. Axel Rauschmayer
[email protected]
rauschma.de
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss