Submitted
This exercise was difficult because I didn't want to change my approach to solving it. Eventually, It was obvious that I needed to delete a good portion of my code and start again with a simpler approach.
I took on this challenge with the idea of practicing end-to-end (e2e) testing using Vitest. And people, let me tell you that this is a great exercise for practicing unit tests and e2e tests because if you need to refactor your code and make it simpler or less convoluted, the tests will save your life.