Please code “this kind of thing,” instead of “elegantly.” Please.
Why? Because, at a glance, I can see and understand what the first example is doing, and, even there comes a time where one of the many cases is slightly different, I can still easily maintain it and be entirely certain that the changed code still works. In your “elegant” example, every single one of these cases has been coupled to one another. It is no longer possible to see “at a glance” what the code is intended to do, nor to be certain that in all cases it actually does it.
Generally speaking, don’t try to economize on source-code statements, especially not at the expense of expressiveness and maintainability as has been done here.