Merge map values

Mohan.Radhakrishnan at cognizant.com Mohan.Radhakrishnan at cognizant.com
Tue Apr 28 12:42:29 UTC 2015


I agree this is not about the ES6 spec. But the answers helped because I was trying to understand ES6’s arrow function that is similar to lambdas.


Thanks.

From: Andrea Giammarchi [mailto:andrea.giammarchi at gmail.com]
Sent: Tuesday, April 28, 2015 6:02 PM
To: Kevin Smith
Cc: Axel Rauschmayer; Radhakrishnan, Mohan (Cognizant); es-discuss list
Subject: Re: Merge map values

Not sure why everyone went for the `Map` version when in JS every object is basically the equivalent of a `Map` already :-)

```js
let m = Array.from("mainn").reduce((m,k) => ((m[k] = 1 + (m[k] | 0)), m), {});
```

looks a win to me, if you need to check or drop chars from the string I would probably do it once before passing that to `Array.from`

Agreed with Kevin this is rather a StackOverflow like question :-)

Best Regards


On Tue, Apr 28, 2015 at 1:19 PM, Kevin Smith <zenparsing at gmail.com<mailto:zenparsing at gmail.com>> wrote:

Another option:

    var map = new Map;
    Array.from("mainn")
      .map(c => c.toLowerCase())
      .forEach(c => map.set(c, (map.get(c) | 0) + 1));

This kind of question is probably better left for StackOverflow, however.

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss

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/d7b22575/attachment.html>


More information about the es-discuss mailing list