A .pos()

Read(201) Label: get, sequence member, position,

Description:

Get the position of a member in a sequence.

Syntax:

A.pos(x)

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.

Parameters:

A

A sequence object or an expression that returns one.

x

A member.

Options:

@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

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,3].pos@b(3)

Return null

Related functions:

A.pos(x)

A.psort()