@nevware21/ts-utils
    Preparing search index...

    Function arrRotate

    • The arrRotate() method returns a new array with elements rotated by the specified number of positions. Positive values rotate left (elements shift forward), negative values rotate right (elements shift backward). The original array is not modified.

      Type Parameters

      • T

        Identifies the type of array elements

      Parameters

      • theArray: ArrayLike<T>

        The array or array-like object to rotate

      • count: number

        Number of positions to rotate. Positive = right, negative = left

      Returns T[]

      A new array with elements rotated

      0.14.0

      arrRotate([1, 2, 3, 4, 5], 2);      // [3, 4, 5, 1, 2]
      arrRotate([1, 2, 3, 4, 5], -2); // [4, 5, 1, 2, 3]
      arrRotate([1, 2, 3], 0); // [1, 2, 3]
      arrRotate([1, 2, 3], 3); // [1, 2, 3] (full rotation)
      arrRotate([1, 2, 3], 5); // [3, 1, 2] (wraps around)
      arrRotate([1, 2, 3], -5); // [2, 3, 1] (wraps around)
      arrRotate([], 3); // []

      // Array-like objects
      arrRotate({ length: 3, 0: "a", 1: "b", 2: "c" }, 1); // ["b", "c", "a"]