Altametrics interview question

Presented me with a more complex typescript question