Nice article! Everyone seems to forget my two favorite functions though, some and every
If you've ever written something like
constitems=[1,9,4,2,42];// checks if any item in the array matches the predicatevarhasAnyBigItems=items.some(item=>item>10));// checks if every item in the array matches the predicatevarallPositive=items.every(item=>item>0);
If you ever find yourself checking the length property after items.filter(), you can likely use some or every to do the same thing without the array generation penalty.
Nice article! Everyone seems to forget my two favorite functions though,
some
andevery
If you've ever written something like
If you ever find yourself checking the
length
property afteritems.filter()
, you can likely usesome
orevery
to do the same thing without the array generation penalty.Really nice!!! I'm a Python programmer and didn't know JS has functions like that!! Congrats bro