Wrap redundant reduce and reduceRight code in helper

The loops could be further abstracted, but I didn't like how it looked after going that far

Fixes #1734 
What are you thinking of the loop exit condition

```
for (; i >= 0 && i < length; i += dir) {

}
```

Anyway, it may save some code but I doubt it will be JITed very well. Feel free to make a follow up change set