rank
Table of Contents
Overview
The rank function operates on a collection of numerical values. It sorts them in descending order (by default) and returns the rank (order) of the requested element in that order.
Note:
- The numerical values should be available inside a collection.
- Invoking the rank function on values other than numbers or decimals will result in a runtime error.
Return Type
- NUMBER / DECIMAL
Syntax
<variable> = <collection>.rank(<number>, [<sort_order>]);
where,
Parameter | Data type | Description |
<variable> | NUMBER | Variable which contains the rank of the requested element. |
<numberCollection> | COLLECTION | The collection of numerical values. |
<number> | NUMBER / DECIMAL | The numerical value for which the rank has to be determined. |
<sort_order> (optional) | TEXT | The rank is determined based on elements sorted in the descending order by default. This parameter is used to reverse the sorting order. This parameter takes "asc" (case-insensitive) as a value. |
Examples
marks = Collection(300,455,124,926,780); order = marks.rank(300); // the variable order is assigned the value 4 marks = Collection(120.12,65,300.46,600.25,80.5); order = marks.rank(80.5, "asc"); // the variable order is assigned the value 2 as the elements are sorted in ascending order marks = Collection(120.12,65,300.46,600.25,80.5); order = marks.rank(100); // A run-time error ('List contains invalid(TEXT) entries hence' can not be cast to 'valid list and perform desired operations') will be thrown as there is no such element