You could simplify the implementation with reduce.
Ivan Dilchovski
1

How would you do that? I thought about using reduce here but I finally chose a more procedural solution because I think it’s clearer.

But I’d really like to see a more functional solution!