Solution to implement map with reduce