Description:
Get positions of members of a sequence in another sequence.
Syntax:
A.pos(x)
Note:
The function gets positions of all members of sequence x in sequence A and returns null if it cannot find positions for all members of x.
Parameter:
A |
A sequence |
x |
A sequence |
Option:
@i |
Get a monotonically increasing integer sequence |
@c |
Get position of the continuous sub-sequence x of sequence A when it appears the first time |
@b |
A is by default assumed as an ordered sequence and use binary search to get the position increasingly or decreasingly |
Return value:
Integer sequence
Example:
[6,2,1,4,6,3,7,8].pos([1,4, 6]) |
[3,4,1]; get an integer sequence of positions of members in sequence [1,4,6] in sequence [6,2,1,4,6,3,7,8] when they first appear in the latter. |
[6,2,1,4,6,3,7,8].pos([1,4, 9]) |
null; return null as member 9 of sequence [1,4, 9]; cannot be found in sequence [6,2,1,4,6,3,7,8]. |
[6,2,1,4,6,3,7,8].pos@i([1,4,6]) |
[3,4,5]; use @i option to get a monotonically increasing integer sequence of positions of members in sequence [1,4,6] in sequence [6,2,1,4,6,3,7,8]. |
[6,2,1,4,6,3,7,8].pos([3,6,4]) |
[6,1,4]. |
[6,2,1,4,6,3,7,8].pos@i([3,6,4]) |
null; use @i option but return null because sub-sequence [3,6,4] whose members’ positions in sequence [6,2,1,4,6,3,7,8] isn’t a monotonically increasing integer sequence does not exist. |
[2,1,4,6,3,7,8,4,6,1].pos@c([4,6]) |
3; get position of the continuous sub-sequence [4,6] in sequence [2,1,4,6,3,7,8,4,6,1] when it first appears. |
[1,2,3,4,6,7,8].pos@b([3,1,4,6]) |
[3,1,4,5]; [1,2,3,4,6,7,8] is an ordered sequence and use binary search to get the position. |
Related function: