Upstox interview question

write a higher order for reduce function in swift