Shifts array elements left or right by n positions with wraparound. Access via MCP in Cursor or Windsurf, or REST at `/v1/array/rotate`. Pass `[1,2,3,4]` with `n=2` to get `[3,4,1,2]`. Handles negative rotations and preserves original array length perfectly.
curl "https://tinyfn.io/v1/array/rotate" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/array/rotate', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests
response = requests.get('https://tinyfn.io/v1/array/rotate',
headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)
Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's array tools:
{
"mcpServers": {
"tinyfn-array": {
"url": "https://tinyfn.io/mcp/array",
"headers": {
"X-API-Key": "YOUR_API_KEY"
}
}
}
}
Positive n rotates left (elements move toward index 0), negative n rotates right. `rotate([1,2,3], 1)` returns `[2,3,1]`, while `rotate([1,2,3], -1)` returns `[3,1,2]`.
The function uses modulo arithmetic, so rotating by array length + k is identical to rotating by k. Rotating `[1,2,3]` by 5 positions equals rotating by 2.
Yes, rotation works on any JSON array regardless of element type. You can rotate arrays of numbers, strings, objects, or mixed types while preserving element integrity.
Call the MCP tool directly with your array and rotation count. Perfect for data preprocessing, implementing circular buffers, or sliding window operations in AI-assisted development.
Returns a new rotated array without modifying the original. This functional approach ensures your source data remains unchanged and enables safe chaining with other operations.
Get your free API key and start using Array Rotate in seconds.
Get Free API Key