Made reduceRight pass in the original array and corrected its indexing