shift()

Read(259) Label: shift,

Here’s how to use shift() function.

shift()

Description:

Perform a shift operation.

Syntax:

shift(x,s)

Note:

Shift left if s<0; shift right if s>0.

Parameters:

x

The expression based on which you perform the shift operation

s

An integer

Options:

@s

When shifting right, shift a sign into the leftmost position and shif a zero to this position by default

Return value:

An integer

Example:

shift(13,2)

3

A.shift()

Description:

Get a shuffled sequence.

Syntax:

A.shift(i,s)

Note:

The function traverses members of sequence A. During the traversal, if the sequence number of the current member is greater than or equal to parameter i and, at the same time, less than or equal to [A.len()-s], return the sth member after the current one; otherwise, return the current member. A.len() is the length of sequence A. If the sum of i and s is greater than A.len(), the sequence won’t be shuffled.

Parameters:

i

The starting position, which is a positive integer; 1 is the default value

s

The offset value, which is a positive integer; 1 is the default value

Return value:

A sequence

Example:

 

A

 

1

[1,2,3,4,5,6,7,8,9,10]

 

2

=A1.shift(4,3)

3

=to(10).new(~:id,~*~:value)

 

4

=A3.shift(3,2)

Before shifting:

After shifting: