Function rotate

  • Rotate the elements of an array in-place.

    Type Parameters

    • T

    Parameters

    • array: MutableArrayLike<T>

      The mutable array-like object of interest.

    • delta: number

      The amount of rotation to apply to the elements. A positive value will rotate the elements to the left. A negative value will rotate the elements to the right.

    • start: number = 0

      The index of the first element in the range to be rotated, inclusive. The default value is 0. Negative values are taken as an offset from the end of the array.

    • stop: number = -1

      The index of the last element in the range to be rotated, inclusive. The default value is -1. Negative values are taken as an offset from the end of the array.

      Complexity

      Linear.

      Undefined Behavior

      A delta, start, or stop which is non-integral.

      Example

      import { ArrayExt } from '@lumino/algorithm';

      let data = [0, 1, 2, 3, 4];
      ArrayExt.rotate(data, 2); // [2, 3, 4, 0, 1]
      ArrayExt.rotate(data, -2); // [0, 1, 2, 3, 4]
      ArrayExt.rotate(data, 10); // [0, 1, 2, 3, 4]
      ArrayExt.rotate(data, 9); // [4, 0, 1, 2, 3]
      ArrayExt.rotate(data, 2, 1, 3); // [4, 2, 0, 1, 3]

    Returns void

Generated using TypeDoc