# ptop()

Here’s how to use ptop() function.

A.ptop()

Description:

Get the sequence numbers of the n smallest members in a sequence.

Syntax:

A.ptop(n,x)

Note:

The function sorts members of sequence A according to expression x and returns a sequence comprising the sequence numbers of the n smallest members in the given sequence. List both if the smallest member and the largest member are the same. n must be supplied; if n is 0, return null. The absence of x is equivalent to ~; and if the value of x is 0, sorting action won’t be performed.

Parameters:

 A A sequence x Sorting expression n An integer

Options:

 @1 Return a single value if n is ±1

Return value:

A sequence composed of sequence numbers of specified members

Example:

 A 1 [a,c,e,g,f,d,b] 2 =A1.ptop(3,~) [1,7,2] 3 =A1.ptop(3) Same as A2, as x is not supplied 4 =demo.query("select * from EMPLOYEE") 5 =A4.ptop(3,HIREDATE) [8,18,203] 6 =A1.ptop(-1) 4 7 =A4.ptop(3,0) [1,2,3] 8 =A1.ptop@1(-1) 9 [a,c,e,g,f,d,b,a] 10 =A9.ptop(1,~) [1,8]

Related functions: