implemented underscore reduce function