Reason being that “.some()” returns true/false, whereas “.find()” returns the matching value, and if that value is falsy (ex: 0) it will be erroneously omitted from the results.
See the other comment in this thread. .some is more appropriate since it only returns a Boolean. Problem is that find’s output is ambiguous if it finds a value that is falsey. Assuming undefined is never a value, then !== undefined with find will save you, but at that point, might as well use some
I've heard inexperienced devs justify this kind of coding as "verbosity in exchange for maintainability" as if adding abstractions somehow always makes something less maintainable, ugh.
86
u/orebright Jan 04 '23
Why complicate things?
21
u/WheresTheSauce Jan 04 '23
There is so much shit like this in one of the codebases I'm working with right now and it just pains me to no end.
4
u/abenzenering Jan 04 '23
Real question: was the PR approved? Lol 😟
46
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 04 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!