<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="utility">
	<name>reduce()</name>
	<summary>Apply a callback function against and accumulator and each element in the Api's result set (left-to-right).</summary>
	<since>1.10</since>

	<type type="function">
		<signature>reduce( fn [, initialValue ] )</signature>
		<description>Apply a callback function against and accumulator and each element in the Api's result set.</description>
		<parameter type="function" name="fn">
			Callback function which is called for each item in the API instance result set. The callback is called with four parameters:

			* Current accumulator value, or `initialValue` if supplied in the first callback
			* Current element value
			* The element index in the result set
			* The API instance being traversed

			The callback should return the value to be used as the accumulator for the next loop (first parameter in the callback).
		</parameter>
		<parameter type="*" name="initialValue" default="">
			Value to use as the first argument of the first call to the `fn` callback.
		</parameter>
		<returns type="*">Result from the final call to the `fn` callback function.</returns>
	</type>

	<description>
		This method can be used to accumulate data from a result set into a single value. A good example is summing the values from a column of data. A more complete definition of the Array reduce method, which this method is based upon, can be found on the [Mozilla MDN documentation for `reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).

		Note that the traversal of the elements in the result set in this method is left-to-right (i.e. 0 to `length`). `dt-api reduceRight()` is available for transversal in the opposite direction.

		This method makes use of the fact that DataTables API objects are "array like", in that they inherent a lot of the abilities and methods of the Javascript `Array` type.

		In this case, this method is a proxy for the Javascript `Array.prototype.reduce` method and is provided as a utility method for the DataTables API. For more information about the original method, please refer to the [Mozilla MDN documentation for `reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce). In browsers which do not support `reduce` natively, a polyfill is provided to allow this DataTables method to operate as expected.
	</description>

	<example title="Sum the data in a column"><![CDATA[
var table = $('#example').DataTable();

var sum = table
	.column( 0 )
	.data()
	.reduce( function ( a, b ) {
		return a + b;
	} );

]]></example>

</dt-api>