Array Reduce Function Typescript Interview Question