Function rotateArray

  • Rotate the elements of an array by an amount specified. Essentially increments the index of every element by the amount, and elements at the end wrap round to the start.

    Returns

    the rotated array

    Example

    rotateArray([1, 2, 3]) === [3, 1, 2]
    

    Example

    rotateArray(['a', 'b', 'c'], -1) === ['b', 'c', 'a']
    

    Example

    rotateArray(['🍎', '🍐', '🍋'], 2) === ['🍐', '🍋', '🍎']
    

    Type Parameters

    • T

    Parameters

    • arr: T[]

      array to rotate

    • amount: number = 1

      number of elements to rotate by (default: 1)

    Returns T[]

Generated using TypeDoc