ROTATE

Rotates the elements in an array by any number of steps.

Syntax 

ROTATE(array, steps)

Usage examples 

Example 1

Input

1
{
2
"array": [
3
"north",
4
"south",
5
"east",
6
"west"
7
]
8
}

Formula

ROTATE(array)

Output

1
[
2
"south",
3
"east",
4
"west",
5
"north"
6
]

Example 2

Accepts a second argument to rotate by a number of steps

Input

1
{
2
"array": [
3
1,
4
2,
5
3,
6
4,
7
5,
8
6,
9
7,
10
8,
11
9,
12
10
13
]
14
}

Formula

ROTATE(array, 7)

Output

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

Example 3

Accepts negative numbers to rotate in the opposite direction

Input

1
{
2
"array": [
3
"apple",
4
"banana",
5
"cherry",
6
"date"
7
]
8
}

Formula

ROTATE(array, -1)

Output

1
[
2
"date",
3
"apple",
4
"banana",
5
"cherry"
6
]
Was this helpful?