Using the reduce function