Sets plus JSON

Rick Waldron waldron.rick at gmail.com
Wed Oct 3 12:59:11 PDT 2012


On Wed, Oct 3, 2012 at 2:44 PM, Dean Landolt <dean at deanlandolt.com> wrote:

>
>
> On Wed, Oct 3, 2012 at 2:19 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>>
>>
>> On Wed, Oct 3, 2012 at 2:04 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>>
>>>
>>>
>>> On Wed, Oct 3, 2012 at 1:43 PM, Brandon Benvie <
>>> brandon at brandonbenvie.com> wrote:
>>>
>>>> Another options for Maps is to represent them as an array of [key,
>>>> value].
>>>
>>>
>>> Which is a rough approximation of what a Map looks like internally.
>>>
>>>
>>>
>> Sorry, this is incorrect. Map looks more like:
>>
>> [key1, key2]
>> [value1, value2]
>>
>> Sorry for confusion
>>
>>
> I image it looking something like [key1, value1, key2, value2...] -- index
> % 2 implies values. Anything more would mean an awful lot of unnecessary
> allocations. I don't see why this wouldn't be sufficient for the json form
> as well, especially if the language had something like a take2 iterator.
>

My correction was missing outer brackets... typed in a hurry. It makes more
sense like this:

var keys = { a: {}, b: {}, g: {} },
    map = new Map([ [keys.a , "alpha"], [keys.b, "beta"], [keys.g, "gamma"]
]);

console.log( map.get(keys.a) ); // "alpha"
console.log( map.get(keys.b) ); // "beta"
console.log( map.get(keys.g) ); // "gamma"


ie. the structure:

[ [keys.a , "alpha"], [keys.b, "beta"], [keys.g, "gamma"] ]


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121003/4aaaddf8/attachment.html>


More information about the es-discuss mailing list