Loading TOC...

WordsSearch.map

WordsSearch.map(
   $mapper as objectOrFuncRef
) as WordsSearch

Summary

Specifies a function similar to Array.prototype.map() to apply to each word within the slice. Exclusive with respect to the reduce() clause.

Parameters
$mapper The mapping function or configuration for the built-in mapper.

Usage Notes

Your custom mapper function is invoked on each word in the current slice. Your custom mapper should have the following signature:

function (currentItem)

Where the single input is the current word to act on. If the function returns a value, the value is pushed on to the results array.

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

See Also

Example


// Returns true if the input is on my black list
function isInBlackList(word) {...};

const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.words('title')
  .slice(0,3)
  .map(function (word) {
    return isInBlackList(word) ? undefined : word
  })
  .result()

// Result: An array of words in 'title' word lexicon that are not blacklisted
   

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy