Hello @Francesco_Garrisi welcome to the forum! Take a look at this playground, it piggybacks on the last element being empty (although it might not be the case in a real-life case).
I’d like to understand your use case a bit better, because it seems like a small change to your data model would simplify this problem a lot.
For example, how are results
grouped by? You could solve the issue using a key-value pattern, like this