javascript-collections-framework
    Preparing search index...

    Function swap

    • Exchanges the elements at i and j of list; nothing is written when i === j.

      Time: O(1) plus two get and two set calls.

      Parameters

      • list: List<unknown>

        The list.

      • i: number

        One index.

      • j: number

        The other index.

      Returns void

      TypeError when list is not a list from this library.

      IndexOutOfBoundsError when either index is out of bounds; the list is unchanged.

      const list = new ArrayList(['a', 'b', 'c'])
      swap(list, 0, 2) // list is now ['c', 'b', 'a']