reduceRight function done