array_rotate_left()
Rotates values inside a dynamic
array to the left.
Syntax
array_rotate_left(
array, rotate_count)
Arguments
- array: Input array to rotate, must be dynamic array.
- rotate_count: Integer specifying the number of positions that array elements will be rotated to the left. If the value is negative, the elements will be rotated to the right.
Returns
Dynamic array containing the same amount of the elements as in original array, where each element was rotated according to rotate_count.
See also
- For rotating array to the right, see array_rotate_right().
- For shifting array to the left, see array_shift_left().
- For shifting array to the right, see array_shift_right().
Examples
-
Rotating to the left by two positions:
print arr=dynamic([1,2,3,4,5]) | extend arr_rotated=array_rotate_left(arr,2)
Results
arr | arr_rotated |
---|---|
[1,2,3,4,5] | [3,4,5,1,2] |
-
Rotating to the right by two positions by using negative rotate_count value:
print arr=dynamic([1,2,3,4,5]) | extend arr_rotated=array_rotate_left(arr, -2)
Results
arr | arr_rotated |
---|---|
[1,2,3,4,5] | [4,5,1,2,3] |