Yes I know, I’m saying my solution technically works now after changing typo and changing it to one ! but is it bad to have three returns new question.
I much prefer the return early style over a giant if/else chain. Of course everyone has their own opinions, but I would say that in the current zeitgeist else is generally avoided.
Yeah, sometimes people get excessively verbose in weird ways.
I come from a C background, so I have mixed feelings about early return. It can tidy up code, but I tend to use it sparingly. I try to limit the number of ways to exit a function.
I think the sweet spot for early returns is found in the land of small, pure functions, which I imagine is far less popular in C than in JS these days. Completely talking from my butt though, I don’t know anything but web programming.
I think it depends upon application more than language? Scientific code often can take 100+ lines to do ‘one thing’ in a function. That’s my main area of experience.
But tying back to OP’s question, I see multiple return statements as a fine style choice in this code. I’d just ditch the duplicate if statement.