Re: es-discuss Digest, Vol 135, Issue 48

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

Ben Fletcher
Does the `[...oldArr, ...elementsToPushArr]` pattern take care of that for you? I've always assumed it's much less performant than your form would be, but I (naively) suppose the implementation could be optimized like anything else

On Wed, May 23, 2018 at 8:01 AM <[hidden email]> wrote:
Send es-discuss mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.mozilla.org/listinfo/es-discuss
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of es-discuss digest..."
Today's Topics:

   1. Array.prototype.append ? (Jordi Bunster)



---------- Forwarded message ----------
From: Jordi Bunster <[hidden email]>
To: "[hidden email]" <[hidden email]>
Cc: 
Bcc: 
Date: Wed, 23 May 2018 02:45:25 +0000
Subject: Array.prototype.append ?
Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself? It would be reduce-friendly, same as Set.prototype.add and Map.prototype.set.

Someone has to have, right? 😊
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

Alexander Lichter

An optimization would be great because in comparison to the existing concat method, rest/spread is significantly slower at the moment (see https://jsperf.com/single-array-composition)


On 23.05.2018 18:34, Ben Fletcher wrote:
Does the `[...oldArr, ...elementsToPushArr]` pattern take care of that for you? I've always assumed it's much less performant than your form would be, but I (naively) suppose the implementation could be optimized like anything else

On Wed, May 23, 2018 at 8:01 AM <[hidden email]> wrote:
Send es-discuss mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.mozilla.org/listinfo/es-discuss
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of es-discuss digest..."
Today's Topics:

   1. Array.prototype.append ? (Jordi Bunster)



---------- Forwarded message ----------
From: Jordi Bunster <[hidden email]>
To: "[hidden email]" <[hidden email]>
Cc: 
Bcc: 
Date: Wed, 23 May 2018 02:45:25 +0000
Subject: Array.prototype.append ?
Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself? It would be reduce-friendly, same as Set.prototype.add and Map.prototype.set.

Someone has to have, right? 😊
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

T.J. Crowder-2
On Wed, May 23, 2018 at 5:56 PM, Alexander Lichter <[hidden email]> wrote:
> An optimization would be great because in comparison to the existing concat
> method, rest/spread is significantly slower at the moment (see
> https://jsperf.com/single-array-composition)

There's a limit to how much optimization can address the fact that `[...original, ...additions]` has to create a new array. And creating the array is significant, as we can see in the difference between `concat` and `push`: https://jsperf.com/concat-vs-push-number-42

I've often wanted an `Array.prototype.append` (often enough I've been known to add it on occasion; obviously only in app/page code, not in lib code). It would be a good addition in my view. I tend to suspect the name isn't web-safe, though. So that would need investigation and design.

The polyfill is trivial:

```js
Object.defineProperty(Array.prototype, "append", {
    value: function(...sources) {
        for (let o = 0, olen = sources.length; o < olen; ++o) {
            const source = sources[o];
            for (let i = 0, ilen = source.length; i < ilen; ++i) {
                this.push(source[i]);
            }
        }
        return this;
    },
    writable: true,
    configurable: true
});
```

I've avoided iterators and such as a first pass at optimization (and it seems to do okay: https://jsperf.com/push-vs-append-number-42/1). Didn't use `push.apply` because of the limits it has on it in some implementations. This version assumes all entries are array-like and should have their entries added to the array on which it's called. There are a lot of other designs one could make, though. Just one argument (you can always chain); a flattening version; etc., etc.

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

Jordi Bunster
Cool!

So for me, the point would be symmetry with Map and Set.

As such my poly would go like so:

```js
Object.defineProperty(Array.prototype, "append", {
    writable: true,
    configurable: true,
    value: function(arg) {
        this.push(arg);
        return this;
    }
});
```

(Which is basically what I end up doing with && in a => in reduce() calls...)

> On Wed, May 23, 2018 at 5:56 PM, Alexander Lichter <[hidden email]> wrote:
> > An optimization would be great because in comparison to the existing concat
> > method, rest/spread is significantly slower at the moment (see
> > https://jsperf.com/single-array-composition)
>
> There's a limit to how much optimization can address the fact that `[...original, ...additions]` has to create a new array. And creating the array is significant, as we can see in the difference between `concat` and `push`: https://jsperf.com/concat-vs-push-number-42
>
> I've often wanted an `Array.prototype.append` (often enough I've been known to add it on occasion; obviously only in app/page code, not in lib code). It would be a good addition in my view. I tend to suspect the name isn't web-safe, though. So that would need investigation and design.
>
> The polyfill is trivial:
>
> ```js
> Object.defineProperty(Array.prototype, "append", {
>     value: function(...sources) {
>         for (let o = 0, olen = sources.length; o < olen; ++o) {
>             const source = sources[o];
>             for (let i = 0, ilen = source.length; i < ilen; ++i) {
>                 this.push(source[i]);
>             }
>         }
>         return this;
>     },
>     writable: true,
>     configurable: true
> });
>
> ```
>
>
> I've avoided iterators and such as a first pass at optimization (and it seems to do okay: https://jsperf.com/push-vs-append-number-42/1). Didn't use `push.apply` because of the limits it has on it in some implementations. This version assumes all entries are array-like and should have their entries added to the array on which it's called. There are a lot of other designs one could make, though. Just one argument (you can always chain); a flattening version; etc., etc.
>
>
> -- T.J. Crowder
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

T.J. Crowder-2
On Wed, May 23, 2018 at 6:49 PM, Jordi Bunster <[hidden email]> wrote:
> Cool!
>
> So for me, the point would be symmetry with Map and Set.

Are you saying you'd want to have `append` on them as well?

> As such my poly would go like so:

>
> ```js
> Object.defineProperty(Array.prototype, "append", {
>     writable: true,
>     configurable: true,
>     value: function(arg) {
>         this.push(arg);
>         return this;
>     }
> });

For some reason, in my head you were calling `append` with an array, not discrete items. Not sure why that was. Silly of me. I've rarely needed an `append` for individual items, my use cases have generally been appending an array to another array. But that could be its own separate thing (`appendArray`). (I **wouldn't** overload it as with `concat`.)

I'd lean toward accepting as many as are given, as with `push`:

```js
Object.defineProperty(Array.prototype, "append", {
    value: function(...items) {
        for (let i = 0, len = source.length; i < len; ++i) {
            this.push(item[i]);
        }
        return this;
    },
    writable: true,
    configurable: true
});
```

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

Jordan Harband
In reply to this post by T.J. Crowder-2
`array.push(...sources)`, not sure why we'd need "append".

On Wed, May 23, 2018 at 1:25 PM, T.J. Crowder <[hidden email]> wrote:
On Wed, May 23, 2018 at 5:56 PM, Alexander Lichter <[hidden email]> wrote:
> An optimization would be great because in comparison to the existing concat
> method, rest/spread is significantly slower at the moment (see
> https://jsperf.com/single-array-composition)

There's a limit to how much optimization can address the fact that `[...original, ...additions]` has to create a new array. And creating the array is significant, as we can see in the difference between `concat` and `push`: https://jsperf.com/concat-vs-push-number-42

I've often wanted an `Array.prototype.append` (often enough I've been known to add it on occasion; obviously only in app/page code, not in lib code). It would be a good addition in my view. I tend to suspect the name isn't web-safe, though. So that would need investigation and design.

The polyfill is trivial:

```js
Object.defineProperty(Array.prototype, "append", {
    value: function(...sources) {
        for (let o = 0, olen = sources.length; o < olen; ++o) {
            const source = sources[o];
            for (let i = 0, ilen = source.length; i < ilen; ++i) {
                this.push(source[i]);
            }
        }
        return this;
    },
    writable: true,
    configurable: true
});
```

I've avoided iterators and such as a first pass at optimization (and it seems to do okay: https://jsperf.com/push-vs-append-number-42/1). Didn't use `push.apply` because of the limits it has on it in some implementations. This version assumes all entries are array-like and should have their entries added to the array on which it's called. There are a lot of other designs one could make, though. Just one argument (you can always chain); a flattening version; etc., etc.

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

Tab Atkins Jr.
On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
> `array.push(...sources)`, not sure why we'd need "append".

From the original email (a bit buried and hard to find due to broken
threading, admittedly):

> Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself?

The point is x.append(y) returning x, whereas x.push(y) returns y.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

Andrea Giammarchi-2
Just one thought ...
```js
Object.defineProperty(Array.prototype, "append", {
    value(...sources) {
        this.push(...[...sources]);
        return this;
    },
    writable: true,
    configurable: true
});
```

... but also another one ...
```js
(array.push(...sources), array)
```

it seems to little of an improvement to become new Array method, I am already confused with includes and contains that append and push, when Sets have add, might cause me unnecessary headaches.

Regards



On Wed, May 23, 2018 at 10:14 PM, Tab Atkins Jr. <[hidden email]> wrote:
On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
> `array.push(...sources)`, not sure why we'd need "append".

From the original email (a bit buried and hard to find due to broken
threading, admittedly):

> Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself?

The point is x.append(y) returning x, whereas x.push(y) returns y.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

Isiah Meadows-2
In reply to this post by T.J. Crowder-2
Since `Array.prototype.push` is variadic, I don't see how this would be any improvement on the status quo (which isn't that bad to begin with).

On Wed, May 23, 2018, 13:57 T.J. Crowder <[hidden email]> wrote:
On Wed, May 23, 2018 at 6:49 PM, Jordi Bunster <[hidden email]> wrote:
> Cool!
>
> So for me, the point would be symmetry with Map and Set.

Are you saying you'd want to have `append` on them as well?

> As such my poly would go like so:

>
> ```js
> Object.defineProperty(Array.prototype, "append", {
>     writable: true,
>     configurable: true,
>     value: function(arg) {
>         this.push(arg);
>         return this;
>     }
> });

For some reason, in my head you were calling `append` with an array, not discrete items. Not sure why that was. Silly of me. I've rarely needed an `append` for individual items, my use cases have generally been appending an array to another array. But that could be its own separate thing (`appendArray`). (I **wouldn't** overload it as with `concat`.)

I'd lean toward accepting as many as are given, as with `push`:

```js
Object.defineProperty(Array.prototype, "append", {
    value: function(...items) {
        for (let i = 0, len = source.length; i < len; ++i) {
            this.push(item[i]);
        }
        return this;
    },
    writable: true,
    configurable: true
});
```

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: es-discuss Digest, Vol 135, Issue 48

T.J. Crowder-2
In reply to this post by Andrea Giammarchi-2
We have two threads going on this with the same (and differeing)
points being raised in both, let's pick it up in the better-named
["Array.prototype.append?"
thread](https://esdiscuss.org/topic/array-prototype-append).

-- T.J. Crowder
Farsight Software Ltd | 20-22 Wenlock Road, London N1 7GU | Company #8393428

[hidden email] | Office: +44 (0)20 3034 0132 -
Mobile: +44 (0)7717 842 414



If you've received this message in error, please let us know by
forwarding it to [hidden email] and then delete it from
your system. Please don't copy it or disclose its contents to anyone.
Separately, note that email sent over the internet without a digital
signature may be modified en route.


On Wed, May 23, 2018 at 10:15 PM, Andrea Giammarchi
<[hidden email]> wrote:

> Just one thought ...
> ```js
> Object.defineProperty(Array.prototype, "append", {
>     value(...sources) {
>         this.push(...[...sources]);
>         return this;
>     },
>     writable: true,
>     configurable: true
> });
> ```
>
> ... but also another one ...
> ```js
> (array.push(...sources), array)
> ```
>
> it seems to little of an improvement to become new Array method, I am
> already confused with includes and contains that append and push, when Sets
> have add, might cause me unnecessary headaches.
>
> Regards
>
>
>
> On Wed, May 23, 2018 at 10:14 PM, Tab Atkins Jr. <[hidden email]>
> wrote:
>>
>> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
>> > `array.push(...sources)`, not sure why we'd need "append".
>>
>> From the original email (a bit buried and hard to find due to broken
>> threading, admittedly):
>>
>> > Has anyone ever suggested Array.prototype.append as an
>> > Array.prototype.push which returns the array itself?
>>
>> The point is x.append(y) returning x, whereas x.push(y) returns y.
>>
>> ~TJ
>> _______________________________________________
>> es-discuss mailing list
>> [hidden email]
>> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

T.J. Crowder-2
In reply to this post by Isiah Meadows-2
On Wed, May 23, 2018 at 11:06 PM, Isiah Meadows <[hidden email]> wrote:
>
> Since `Array.prototype.push` is variadic, I don't see how this would be any improvement on the status quo (which isn't that bad to begin with).

On Wed, May 23, 2018 at 9:14 PM, Tab Atkins Jr. <[hidden email]> wrote:
> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
>> `array.push(...sources)`, not sure why we'd need "append".
>
> From the original email (a bit buried and hard to find due to broken
> threading, admittedly):
>
>> Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself?
>
> The point is x.append(y) returning x, whereas x.push(y) returns y.

With large arrays you can also run into a platform's stack size limit
with a large number of arguments. I got curious, and unless [my
test][1] is significantly flawed, that limit is definitely a factor.
The test uses `dest.push.apply(dest, source)` and works in chunks of
10k entries, reporting the point at which it got a stack error:

* Chrome v66: Between 120k and 130k entries
* Firefox v60: 500k - 510k
* Edge v41: 650k - 660k
* IE11: 250k - 260k
* IE8¹: 5.25M (!) - 5.26M

Using `dest.push(...source)` [instead][2] gave the same numbers as
above on Chrome, Firefox, and Edge.

So two reasons: Returning the array, and not pushing (no pun) the
limit. ~125k entries isn't all that many.

-- T.J. Crowder

¹ *Hey, some people still have to support it (e.g., via transpilation)
-- old embedded IE-based apps in large institutions, etc. I'm just
glad not to be one of them.*

[1]: http://output.jsbin.com/jeperatefi
[2]: http://output.jsbin.com/sucokosipu
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

Andrea Giammarchi-2
I remember doing similar benchmarks for `String.fromCharCode` with a wrap of the native function that was splitting invokes in chunks of 2K chars MAX per operation ... but I think the arguments limits, which is the same you have in `push` is a JS issue as a whole, not something array specific.

As side note, `append(...items) { return this.push(...[...items]), this; }` would be equivalent, but you could also write this without needing to add yet another method to the Array: `(array.push(...items), array)` looks easy to my eyes, nothing new to learn.

My 2 cents

On Thu, May 24, 2018 at 9:33 AM, T.J. Crowder <[hidden email]> wrote:
On Wed, May 23, 2018 at 11:06 PM, Isiah Meadows <[hidden email]> wrote:
>
> Since `Array.prototype.push` is variadic, I don't see how this would be any improvement on the status quo (which isn't that bad to begin with).

On Wed, May 23, 2018 at 9:14 PM, Tab Atkins Jr. <[hidden email]> wrote:
> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
>> `array.push(...sources)`, not sure why we'd need "append".
>
> From the original email (a bit buried and hard to find due to broken
> threading, admittedly):
>
>> Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself?
>
> The point is x.append(y) returning x, whereas x.push(y) returns y.

With large arrays you can also run into a platform's stack size limit
with a large number of arguments. I got curious, and unless [my
test][1] is significantly flawed, that limit is definitely a factor.
The test uses `dest.push.apply(dest, source)` and works in chunks of
10k entries, reporting the point at which it got a stack error:

* Chrome v66: Between 120k and 130k entries
* Firefox v60: 500k - 510k
* Edge v41: 650k - 660k
* IE11: 250k - 260k
* IE8¹: 5.25M (!) - 5.26M

Using `dest.push(...source)` [instead][2] gave the same numbers as
above on Chrome, Firefox, and Edge.

So two reasons: Returning the array, and not pushing (no pun) the
limit. ~125k entries isn't all that many.

-- T.J. Crowder

¹ *Hey, some people still have to support it (e.g., via transpilation)
-- old embedded IE-based apps in large institutions, etc. I'm just
glad not to be one of them.*

[1]: http://output.jsbin.com/jeperatefi
[2]: http://output.jsbin.com/sucokosipu
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

Isiah Meadows-2
In reply to this post by T.J. Crowder-2
Some responses to these, inline.

-----

Isiah Meadows
[hidden email]
www.isiahmeadows.com


On Thu, May 24, 2018 at 3:33 AM, T.J. Crowder
<[hidden email]> wrote:

> On Wed, May 23, 2018 at 11:06 PM, Isiah Meadows <[hidden email]> wrote:
>>
>> Since `Array.prototype.push` is variadic, I don't see how this would be any improvement on the status quo (which isn't that bad to begin with).
>
> On Wed, May 23, 2018 at 9:14 PM, Tab Atkins Jr. <[hidden email]> wrote:
>> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <[hidden email]> wrote:
>>> `array.push(...sources)`, not sure why we'd need "append".
>>
>> From the original email (a bit buried and hard to find due to broken
>> threading, admittedly):
>>
>>> Has anyone ever suggested Array.prototype.append as an Array.prototype.push which returns the array itself?
>>
>> The point is x.append(y) returning x, whereas x.push(y) returns y.

@Jordan, `x.push(y)` returns `x.length` (specifically, the new length).

>
> With large arrays you can also run into a platform's stack size limit
> with a large number of arguments. I got curious, and unless [my
> test][1] is significantly flawed, that limit is definitely a factor.
> The test uses `dest.push.apply(dest, source)` and works in chunks of
> 10k entries, reporting the point at which it got a stack error:
>
> * Chrome v66: Between 120k and 130k entries
> * Firefox v60: 500k - 510k
> * Edge v41: 650k - 660k
> * IE11: 250k - 260k
> * IE8¹: 5.25M (!) - 5.26M

Wait, what? Of all things old IE screws up, this isn't one of them?

>
> Using `dest.push(...source)` [instead][2] gave the same numbers as
> above on Chrome, Firefox, and Edge.
>
> So two reasons: Returning the array, and not pushing (no pun) the
> limit. ~125k entries isn't all that many.

Was the proposal `for (const i of y) x.push(y)`, like a mutable
`concat`? I interpreted it as basically `x.push(y); return x` from the
start, hence why I didn't see the point.

Adding a mutable `concat` variant *would* be useful, though, enough
that I'd like to see it happen. Add an optional mapping callback like
with `Array.from`, and I'd be set. But in this case, I'd rather it be
named `Array.prototype.pushAll`, not `Array.prototype.append`. [1]

[1]: https://github.com/isiahmeadows/array-additions-proposal#arrayprototypepushallitems


>
> -- T.J. Crowder
>
> ¹ *Hey, some people still have to support it (e.g., via transpilation)
> -- old embedded IE-based apps in large institutions, etc. I'm just
> glad not to be one of them.*
>
> [1]: http://output.jsbin.com/jeperatefi
> [2]: http://output.jsbin.com/sucokosipu
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

T.J. Crowder-2
On Thu, May 24, 2018 at 7:02 PM, Isiah Meadows <[hidden email]> wrote:

>> With large arrays you can also run into a platform's stack size limit
>> with a large number of arguments. [snip]
>>
>> * Chrome v66: Between 120k and 130k entries
>> * Firefox v60: 500k - 510k
>> * Edge v41: 650k - 660k
>> * IE11: 250k - 260k
>> * IE8¹: 5.25M (!) - 5.26M
>
> Wait, what? Of all things old IE screws up, this isn't one of them?

I know, right?

> Was the proposal `for (const i of y) x.push(y)`, like a mutable
> `concat`? I interpreted it as basically `x.push(y); return x` from the
> start, hence why I didn't see the point.

Sorry, that's my bad. The original from Jordi Bunster was indeed just
`x.push(y); return x`:

> Has anyone ever suggested Array.prototype.append as an
> Array.prototype.push which returns the array itself? It would be
> reduce-friendly, same as Set.prototype.add and Map.prototype.set.
>
> Someone has to have, right? 😊

Somehow in my head it became a mutating verson of `concat`, possibly
because I've often wanted a mutating version of `concat`, but I don't
recall really wanting a version of `push` that returns the array.

`pushAll` looks good to me. (Re the desugared code: You don't need
that `this.length = index` at the end, though. :-) )

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

Isiah Meadows-2
Yes, I do need that. If you look at the implementation, it makes no
attempt to set it prior, and I designed it to work generically [just
like how `Array.prototype.push` does now][1] (see step 7). I'm aware
that if you assume it's an array, the length will update itself, but
it won't on array-likes.

[1]: https://tc39.github.io/ecma262/#sec-array.prototype.push
-----

Isiah Meadows
[hidden email]
www.isiahmeadows.com


On Fri, May 25, 2018 at 2:46 AM, T.J. Crowder
<[hidden email]> wrote:

> On Thu, May 24, 2018 at 7:02 PM, Isiah Meadows <[hidden email]> wrote:
>>> With large arrays you can also run into a platform's stack size limit
>>> with a large number of arguments. [snip]
>>>
>>> * Chrome v66: Between 120k and 130k entries
>>> * Firefox v60: 500k - 510k
>>> * Edge v41: 650k - 660k
>>> * IE11: 250k - 260k
>>> * IE8¹: 5.25M (!) - 5.26M
>>
>> Wait, what? Of all things old IE screws up, this isn't one of them?
>
> I know, right?
>
>> Was the proposal `for (const i of y) x.push(y)`, like a mutable
>> `concat`? I interpreted it as basically `x.push(y); return x` from the
>> start, hence why I didn't see the point.
>
> Sorry, that's my bad. The original from Jordi Bunster was indeed just
> `x.push(y); return x`:
>
>> Has anyone ever suggested Array.prototype.append as an
>> Array.prototype.push which returns the array itself? It would be
>> reduce-friendly, same as Set.prototype.add and Map.prototype.set.
>>
>> Someone has to have, right? 😊
>
> Somehow in my head it became a mutating verson of `concat`, possibly
> because I've often wanted a mutating version of `concat`, but I don't
> recall really wanting a version of `push` that returns the array.
>
> `pushAll` looks good to me. (Re the desugared code: You don't need
> that `this.length = index` at the end, though. :-) )
>
> -- T.J. Crowder
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array.prototype.append ?

T.J. Crowder-2
On Fri, May 25, 2018 at 1:58 PM, Isiah Meadows <[hidden email]> wrote:
> I'm aware
> that if you assume it's an array, the length will update itself, but
> it won't on array-likes.

Ah, fair enough, supporting array-likes.

-- T.J. Crowder 

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss