javascript-collections-framework
    Preparing search index...

    Function rotate

    • Moves the element at index i of list to index (i + distance) mod size, in place; a negative distance rotates left. Any safe integer is accepted. Elements are written with set, so open iterators and cursors stay valid.

      Time: O(n).

      Parameters

      • list: List<unknown>

        The list to rotate.

      • distance: number

        How far to move each element to the right.

      Returns void

      TypeError when list is not a list from this library or distance is not a number.

      IllegalArgumentError when distance is NaN, infinite, fractional or not a safe integer.

      const list = new ArrayList([1, 2, 3, 4])
      rotate(list, 1) // list is now [4, 1, 2, 3]