2

Normally the index value of Array.prototype.reduce takes the values from 0 until the Array.length. Is it possible to manipulate that value so that it starts from Array.length and descends to 0?

3
  • Can't you just reverse the array? Commented Jun 6, 2016 at 14:03
  • 5
    Or use reduceRight? Commented Jun 6, 2016 at 14:04
  • Or the english one :P Commented Jun 6, 2016 at 14:39

2 Answers 2

3

You can always use Array.prototype.reduceRight() for this.

Sign up to request clarification or add additional context in comments.

Comments

2

No, but you could always do this...

var yourNumber = arr.length - 1 - index;

...or Array.prototype.reduceRight() which will loop from last index to first (in reverse).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.