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

    Function rotateArray2DMajor

    • mutate and rotate the major-axis of a 2D array by the specified amount to the right.

      given a row-major 2D array arr2d, 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

      • arr2d: Array2DRowMajor<T>

        the 2D 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 Array2DRowMajor<T>

      The original array is returned back after the rotation.

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

      const arr2d: Array2DRowMajor<number> = [
      [1 , 2 , 3 ],
      [4 , 5 , 6 ],
      [7 , 8 , 9 ],
      [10, 11, 12],
      [13, 14, 15],
      ]
      rotateArray2DMajor(arr2d, 2)
      assertEquals(arr2d, [
      [10, 11, 12],
      [13, 14, 15],
      [1 , 2 , 3 ],
      [4 , 5 , 6 ],
      [7 , 8 , 9 ],
      ])