All the iteration methods are a specific case of reduce, in that you can implement them all with reduce.
On Mon, Jan 7, 2019 at 11:27 AM Ranando King <[email protected]> wrote: > Isn't that just a specific case of Array.prototype.reduce? > > ```js > const evenNumberCount = [1,2,3,4,5].reduce((acc, val) => { !(val % 2) > && ++acc; }); > ``` > > On Mon, Jan 7, 2019 at 1:12 PM Засим Александр <[email protected]> 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 >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

