Personally, I think they're both sub-optimal because it's not abstracting the arg. check all the way. I think code is easier to reason about if your functions return one data type... and although the examples are returning boolean, in most cases functions return "stuff", and applying that to the examples would make their type "stuff | boolean". As the codebase scales this can be a source of pain for adding new things or finding bugs. The solution is abstracting the param check, and then composing two functions, one function that checks params, followed by the function that modifies "stuff". That way not only is the logic reused cleanly, but the functions will always return "stuff". This has drawbacks of course, as abstracting too much can become unwieldy, however I think there is a lot of power that comes along with it.
Comments
Personally, I think they're both sub-optimal because it's not abstracting the arg. check all the way. I think code is easier to reason about if your functions return one data type... and although the examples are returning boolean, in most cases functions return "stuff", and applying that to the examples would make their type "stuff | boolean". As the codebase scales this can be a source of pain for adding new things or finding bugs. The solution is abstracting the param check, and then composing two functions, one function that checks params, followed by the function that modifies "stuff". That way not only is the logic reused cleanly, but the functions will always return "stuff". This has drawbacks of course, as abstracting too much can become unwieldy, however I think there is a lot of power that comes along with it.