<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.percentile.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.percentile</api:function-name><api:suggest>cts.percentile</api:suggest><api:suggest>cts</api:suggest><api:suggest>percentile</api:suggest><api:function-link mode="xquery" fullname="cts:percentile">/apidoc/8.0/cts:percentile.xml</api:function-link><api:function mode="javascript" name="percentile" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Math Lexicon" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.percentile"><api:summary>
  Returns a sequence of percentile(s) given a sequence of percentage(s).
  This function works like <code xmlns="http://www.w3.org/1999/xhtml">math:percentile</code> except each item in
  the sequence is repeated <code xmlns="http://www.w3.org/1999/xhtml">cts:frequency</code> times before calculating
  the percentiles(s). The function returns the empty sequence if either $arg
  or $p is the empty sequence.
</api:summary><api:params><api:param name="arg" type="xs:double*"><api:param-description>
   The sequence of values. The values should be the result of a lexicon lookup.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>Number[]</api:param-type></api:param><api:param name="p" type="xs:double*"><api:param-description>
  The sequence of percentage(s).
  </api:param-description><api:param-name>p</api:param-name><api:param-type>Number[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:usage>
 <p xmlns="http://www.w3.org/1999/xhtml">This function is designed to take a sequence of values returned
 by a lexicon function (for example, <code>cts:element-values</code>); if you
 input non-lexicon values, the result will be the empty sequence.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// This query assumes an element range index of type 'int'
// is configured for the 'int' element in the database. It
// generates some sample data and then performs the aggregation
// in a separate transaction.

declareUpdate();
for (x=1; x &lt; 11; x++) {
  var obj = new Object();
     for (y=0; y &lt; x; y++){
      {obj.int = y}; };
xdmp.documentInsert(fn.concat(x, ".json"), obj);} 

// After creating the above document, run the following:
//
cts.percentile(
  cts.values([cts.jsonPropertyReference("int", ["type=int"])]),
  [0.25,0.5,0.75])
=&gt;
1.5
4.5
7.5

</pre></api:example></api:function></api:function-page>