Use array.reduce instead of array.forEach

Makes this method a little neater by using reduce instead of forEach.