I'd say what you've done is a stunning case for why foreach, filter, and map are often the LAST methods one should be using, particularly given their overhead — thanks to “callbacks for nothing — is so blasted slow. Same for the mind-numbing derpitude of things like let/const and the painfully and agonizing cryptic arrow function trash...

All of which you basically have doing the job of:

for (var i = 0, student; student = students[i]; i++) {
if (student.class === 'CS') sendInvitation(student.email);

Which is far easier to understand, far cleaner, and would run circles around all that dumbass array processing with callbacks trash since it only needs one flipping loop instead of going full Pakled with three… and even if you dropped down to just one foreach, foreach is STILL slower than an old-school “for”, particulary if you’re working with iterables of object where you can use evaluation on assignment.

I know it’s all hot and trendy right now, but “chaining” operations like that is a REALLY stupid way of writing code, more-so when these fancy but equally stupid array methods get involved.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store