Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
I don't see a big problem with it. If you and your team are happy, then by all means use anything :).
But since you're asking, I would personally name the function something like safeHasElements(array). The reasoning for this is because you (or someone new to the code) might expect atLeastOne to take an array only, and error if it gets null or undefined. But in functional programming, the word "safe" normally implies that things won't throw errors but fail silently instead, or in your case just return false / undefined.
I don't see a big problem with it. If you and your team are happy, then by all means use anything :).
But since you're asking, I would personally name the function something like
safeHasElements(array)
. The reasoning for this is because you (or someone new to the code) might expectatLeastOne
to take an array only, and error if it getsnull
orundefined
. But in functional programming, the word "safe" normally implies that things won't throw errors but fail silently instead, or in your case just returnfalse
/undefined
.Thanks, Spyros - I like your naming suggestion.