Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.38 KB

reduceRight.md

File metadata and controls

48 lines (33 loc) · 1.38 KB

.reduceRight(fn[, initialValue]) => Any

Applies the provided reducing function to every node in the wrapper to reduce to a single value. Each node is passed in as a ReactWrapper, and is processed from right to left.

Arguments

  1. fn (Function): A reducing function to be run for every node in the collection, with the following arguments:
  • value (T): The value returned by the previous invocation of this function
  • node (ReactWrapper): A single-node wrapper around the node being processed
  • index (Number): The index of the node being processed
  1. initialValue (T [optional]): If provided, this will be passed in as the first argument to the first invocation of the reducing function. If omitted, the first node will be provided and the iteration will begin on the second node in the collection.

Returns

T: Returns an array of the returned values from the mapping function...

Example

function Foo() {
  return (
    <div>
      <Bar amount={2} />
      <Bar amount={4} />
      <Bar amount={8} />
    </div>
  );
}
const wrapper = mount(<Foo />);
const total = wrapper.find(Bar).reduceRight((amount, n) => amount + n.prop('amount'), 0);
expect(total).to.equal(14);

Related Methods