Its good and it works. A side note: Having your base cases in the else and else -> else clauses can cause problems in debugging. I usually try to keep base cases apparent and clear and upfront. this is more for reading and understand the function rather than the actual logic.