use reduce instead of for-in