Array Utilities

Array Rotate

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.

API Endpoint

GET /v1/array/rotate

Code Examples

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)

Use via MCP

Add to your AI agent

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"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How does array rotation direction work with positive and negative n values?

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]`.

What happens when rotation count exceeds array length?

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.

Can I rotate arrays of different data types like strings or objects?

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.

How do I integrate array rotation into my MCP workflow with Claude or Cursor?

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.

Does array rotation modify the original array or return a new one?

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.

Try Array Rotate Now

Get your free API key and start using Array Rotate in seconds.

Get Free API Key