Description:
Get the position of a member in a sequence.
Syntax:
A.pos(x,k)
Note:
The function locates member x in sequence A where x may appear repeatedly. Return null if the member cannot be found; return different values according to different options and return the position of the first-found member if no option is present. When parameter k is present, begin the search from the kth member.
Parameter:
A |
A sequence object or an expression that returns one |
x |
A member |
k |
Search from the kth member |
Option:
@b |
Use the binary search to query the location. In this case A is by default an ordered sequence. Both increasing and decreasing are applicable |
@a |
Return an n-integer sequence consisting of sequence numbers of all the members that fulfill the query condition |
@z |
Perform the search backwards from the last member; by default perform the search from the first member |
@s |
With an ordered A and the binary search, return the position of x if it is a member of A; otherwise, return the opposite number for the sequence number representing the position where x can be inserted sequentially |
@p |
Find position of the sequence x, which needs to be treated as a single value, in A, which, in this case, is a sequence of sub-sequences |
@n |
Return the result of the length of A plus 1 if x cannot be found in A. This option and @a are mutually exclusive |
Return value:
A sequence number or a sequence composed of sequence numbers
Example:
|
A |
|
1 |
=[1,2,8,4,5,6,7,8] |
|
2 |
=A1.pos(8) |
3 |
3 |
=A1.pos@a(8) |
[3,8] |
4 |
=A1.pos@z(8) |
8 |
5 |
=A1.pos@az(8) |
[8,3] |
6 |
=A1.pos@z(9) |
null |
7 |
=[1,2,3,4,5,6,7,8].pos@b(5) |
5 |
8 |
=[1,2,4,5,6,7,8].pos@s(3) |
-3 |
9 |
=[[6,2,1,4,6,3,7,8],[1,4,6]].pos@p([1,4,6]) |
2 |
10 |
=[6,2,1,4,6,3,7,8].pos@n(5) |
9 |
11 |
=[6,2,1,4,6,3,7,8].pos(6,3) |
5 |
Note:
If A is not ordered, then options @b and @s should not be used, or they may bring about the incorrect results. For example: [7,6,1,2].pos@b(3) returns null.
Related function: