Some & Every - Functional JavaScript - Supercharged

preview_player
Показать описание
In this mini series, Surma introduces you to the various functional methods that JavaScript Arrays have to offer. In this episode: some & every!

Рекомендации по теме
Комментарии
Автор

This is the best episode in the jQuery err supercharged sheries series.

jakearchibald
Автор

One nice thing is that .some breaks out from the loop as soon as a truthy value is returned, while .every does so with a falsy value.
I *might* have abused this to emulate a `break` while iterating over an array...

MaxArt
Автор

Would be helpful if you talked about browser compatibility too !!

pemessh
Автор

I have a relatively general question. I subscribed to you to have my finger on the pulse of time and see you discuss new emerging technologies, drafts, proposals, and to not fall behind. And yet, this series discusses pretty well-known methods that are half a decade old (ES 5.1), which is somewhat disappointing. Don't you think this conflict of interests deserves a secondary channel? Who is the content on your channel for, exactly?

sonicpawnsyou
Автор

Oh, so these have been available since IE 9!
I've always used array.find instead of "some", and instead of "every" I've used array.find with an inversed predicate, and inversed the result.
Some/every is a bit cleaner though, there are just so many methods to remember...

hrteby
Автор

Would love to hear something about array.flat )

avilde
Автор

I have always used reduce() to implement these. "Some" and "every" is much more readable and they are compatible with all browsers.
some: [].reduce((acc, cv) => acc || test(cv), false)
every: [].reduce((acc, cv) => acc && test(cv), true);

VibhavSinha
Автор

It's gonna take a while to fix all my huge if statements and turn then into array.every {if(...&&...&&...&&..)} and array.some {if(...||...||...||...)}

RafaelCouto