Wrap redundant reduce and reduceRight code in helper

Fixes #1734