Array.prototype.toggle

Jordan Harband ljharb at gmail.com
Fri Feb 7 18:51:16 UTC 2020


I would not be interested in adding any more mutating methods to
Array.prototype, ever. I'd suggest using `.filter` for this.

On Fri, Feb 7, 2020 at 5:29 AM manuelbarzi <manuelbarzi at gmail.com> wrote:

> many things that already provide array could be polyfilled, and probably
> many were polyfills before. it's not about to discuss that, but the chance
> to integrate it in array as a useful feature if most agree it could be so.
>
> On Fri, Feb 7, 2020 at 3:34 PM Augusto Moura <augusto.borgesm at gmail.com>
> wrote:
>
>> To me this is more a use case for using Set instead of arrays, the
>> support is already great and it can be polyfilled. Set is the right data
>> structure to verify if some element is or is not in a collection
>>
>> Em sex., 7 de fev. de 2020 às 08:49, manuelbarzi <manuelbarzi at gmail.com>
>> escreveu:
>>
>>> just a proposal to provide this functionality into array, allowing to
>>> add / remove items in a toggling mechanism shortcut, avoiding the need to
>>> do traversing to locate the indexes and remove them next (i.e. by means of
>>> a polyfill or any other approach).
>>>
>>> ```js
>>> [1, 2, 3, 2, 1].toggle(1) // mutates the original array removing 1,
>>> resulting in [2, 3, 2]
>>> ```
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>>
>> --
>> Atenciosamente,
>>
>> Augusto Borges de Moura
>>
> _______________________________________________
> 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/20200207/3cd5bdc7/attachment.html>


More information about the es-discuss mailing list