Proposal: Array.prototype.count

Pier Bover pierbover11 at gmail.com
Mon Jan 7 19:30:52 UTC 2019


If you need to find the length of a filtered array IMO it makes more sense
and is more obvious to just use filter().

On Mon, Jan 7, 2019 at 1:12 PM Засим Александр <al.zasim at gmail.com> wrote:

> Hi everyone. This is proposal for Array.prototype.count (or countOf)
> method which allow to count specific elements in an array.
>
> ```js
>
> const evenNumberCount = [1, 2, 3, 4, 5].count(num => num % 2 === 0);
>
> ```
>
> Instead of
>
> ```js
>
> const evenNumberCount = [1, 2, 3, 4, 5].filter(num => num % 2 ===
> 0).length;
>
> ```
> _______________________________________________
> 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/20190107/c8b792f9/attachment-0001.html>


More information about the es-discuss mailing list