99% of the time I see usage of Array.prototype.some and Array.prototype.reduce, it would have been much more readable with a manual loop.
-
-
Since everyone seems to have a lot of free time to argue with me on the 4th of July. I also heavily dislike the use of unary ! for boolean negation. eg. !true. I've started writing `=== false`.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
While we’re here I’ll throw in something even more inflammatory. I like this because it lets me “name” the return value and I don’t need to look back at the function name to remember what true or false means. *ducks*pic.twitter.com/Ue4rEDSwJS
-
This is actually the exact pattern I use when I don't have the loop in it's own function.
- 1 more reply
New conversation -
-
-
Also, can someone explain to my why #2 is more functional than #1 besides the fact it literally uses more functions.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Relax, it's just a functional programming style. You'll understand it. For me, #2 is more readable and compact.
-
Buddy, this tweet is extremely condescending.
- 1 more reply
New conversation -
-
-
I find #2 more readable tbph. It describes meaning in english. It would be clearer if there was a none() method on arrays, but even as is I can immediately tell #2 is looking for the existence of an item that meets some requirements. It's really hard for me to parse that in #1.
-
I think after looking at imperative loops for years and years, the brain just adapts to quickly pattern match imperative constructs/early return into the equivalent meaning that is explicit in #2. There's definitely a lot more noise in #1 but I think you just get used to it.
End of conversation
New conversation -
-
-
#2 is more readable if you are used to functional programming in JS. In fact I'd drop the 'function' and 'return' keywords entirely and just use arrow functions.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Strong disagree, but I think the fact that `some` is a poor name has a lot to do with the difference of opinion. Most langs call it any which helps a lot imo
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 