Function shift

  • Type Parameters

    • T

    Parameters

    • arr: T[]
    • n: number

    Returns T[]

    Shift array items by n steps If n > 0 items will shift n steps to the right If n < 0 items will shift n steps to the left

    const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    shift(arr, 3) // => [7, 8, 9, 1, 2, 3, 4, 5, 6]