@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function rotateArray

    • mutate and rotate the given array by the specified amount to the right.

      given an array arr, this function would rotate its rows by the specified amount. a positive amount would rotate the rows to the right, and a negative amount would rotate it to the left.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        the array to be rotated.

      • amount: number

        The number of indexes to rotate the major-axis to the right. positive values rotate right, while negative values rotate left.

      Returns T[]

      The original array is returned back after the rotation.

      import { assertEquals } from "jsr:@std/assert"

      const arr: Array<number> = [1, 2, 3, 4, 5]

      rotateArray(arr, 2)
      assertEquals(arr, [4, 5, 1, 2, 3])

      rotateArray(arr, -3)
      assertEquals(arr, [2, 3, 4, 5, 1])