Loading TOC...

WordsSearch.reduce

WordsSearch.reduce(
   reducer as function,
   seed as anyValue
) as WordsSearch

Summary

Specifies a function similar to Array.prototype.reduce() to apply to each word within the slice.

Parameters
reducer The reducing function.
seed The initial reduction passed to the reducing function.

Usage Notes

Your custom reducer function should have the following signature:

function (prev, current, index, state)

Where the parameters have the following contents:

prev
The value returned by the previous call, or the seed value on the first call.
current
The current word.
index
The number of the current word.
state
A state object with a boolean-valued isLast> property that indicated the last call. You can set it to true to prematurely halt the reduction.

The return from the last call becomes the final reduced result.

You cannot use this method in conjunction with WordsSearch.map.

See Also

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.