Merge map values

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Apr 28 13:02:21 UTC 2015


Moreover `undefined|0` is exactly 0. The `|0` is used in asm.js because it
explicitly declares the intent.

So again, no error in there ;-)

Regards

On Tue, Apr 28, 2015 at 1:58 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> Now you read again the "exercise" and realize that's impossible to have as
> a piutfall ... no, I just used a KISS approach for what I can tell, no
> pitfalls with one single surrogate could happen by specs.
>
> Best Regards
>
> On Tue, Apr 28, 2015 at 1:57 PM, Axel Rauschmayer <axel at rauschma.de>
> wrote:
>
>> With Maps, there are less pitfalls. For example: what if you want to use
>> your version to count words and one of the words is `__proto__`? Most
>> pitfalls can be fixed via `Object.create(null)`, but Maps are more
>> straightforward for data (vs. code).
>>
>> But your version can be easily adapted to Maps, I like the way you use
>> `reduce()`. The `|` should be a `||`.
>>
>> On 28 Apr 2015, at 14:31 , Andrea Giammarchi <andrea.giammarchi at gmail.com>
>> wrote:
>>
>> 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>
>> 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
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>> --
>> Dr. Axel Rauschmayer
>> axel at rauschma.de
>> rauschma.de
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150428/379ddcb6/attachment.html>


More information about the es-discuss mailing list