Set to Array conversions

Rick Waldron waldron.rick at gmail.com
Mon Sep 16 12:02:09 PDT 2013


On Mon, Sep 16, 2013 at 2:59 PM, Rick Waldron <waldron.rick at gmail.com>wrote:

>
>
>
> On Mon, Sep 16, 2013 at 11:33 AM, Angus Croll <anguscroll at gmail.com>wrote:
>
>> I'm trying to figure out the most painless way, given a set, to return
>> the set's values as an array.
>>
>
>
> set.values(); // An array of the set's values
>

Whoops, that's totally wrong information. (that's what I get for rushing
blindly into a thread!) Apologies.

Rick


>
>
>
>>
>> Possibilities:
>> 1) harmony wiki (
>> http://wiki.ecmascript.org/doku.php?id=harmony:iterators&s=iterator)
>> suggests the following, but it is a syntax error in traceur, continuum and
>> "node --harmony"
>>
>
>> let arr = [e for e of mySet];
>>
>
> Just a heads up, that wiki page is out of date (see the notice at the top
> of the page) and shows the old syntax (as shown above). The up-to-date
> syntax is:
>
> let arr = [for (e of mySet) e];
>
> (I realize this is beside the point of the question)
>
> Rick
>
>
>
>>
>> 2)The ES6 standard supports the following production (i.e. expression,
>> not var, before 'for'):
>> *IterationStatement : for ( LeftHandSideExpression of
>> AssignmentExpression ) Statement*
>> (see http://people.mozilla.org/~jorendorff/es6-draft.html#sec-13.6.4.2)
>>
>> which suggests I should be able to do this:
>> let arr = [];
>> for (arr[arr.length-1] of mySet);
>>
>> (I can do the equivalent with for-in) but that also errors in the above
>> three transpilers
>>
>> 3) So then I'm left with the pedestrian:
>> let arr = [];
>> for (e of mySet) {
>>   arr.push(e);
>> }
>>
>> 4) I also wondered if Array.from(mySet) would do the trick but again
>> doesn't seem to pass muster with any of the above transpilers. (continuum
>>  returns a zero length array and the other two don't know Array.from)
>>
>> Wondering if I'm missing something better.
>> thanks
>>
>> Angus
>> @angustweets
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130916/572b42f9/attachment.html>


More information about the es-discuss mailing list