Thanks for your help. I had been putting off tests, but that was the next step in the plan.
Actually, running through a much simpler case in a REPL ended up doing it for me. See my comment about my solution.
But your comments about going back to debugging basics and slowly and methodically validating one piece of logic at a time were what put me back on the right track, so thanks!
Glad you were able to figure it out, nice work!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.