JS Built-ins
← Array154 / 226
ArrayArray.prototype.reduceRightintermediate

Array.prototype.reduceRight() β€” join words in reverse order

πŸ“– Usage Example
const chars = ['a', 'b', 'c']
chars.reduceRight((acc, c) => acc + c, '')  // β†’ 'cba'

Use reduceRight() to reverse-join characters or elements without reversing the original array.

Reversing order with reduceRight

reduceRight() without an initial value starts accumulating from the rightmost element, which naturally reverses the order when joining.

['a', 'b', 'c'].reduceRight((acc, w) => acc + ' ' + w) // 'c b a'
πŸ’‘ Hints (3)
  • β€’ Omit the initial value β€” `reduceRight` uses the last element as the starting accumulator.
  • β€’ Without an initial value, `acc` starts as the rightmost element.
  • β€’ Concatenate with a space: `acc + ' ' + word`.