using reduceRight for doAndContinue instead of copy and reverse,
added polyfill for reduceRight (copy from the MDN)