Function arrSwap

  • Swaps two elements in an array. This function takes an input array and swaps the elements at the specified indices.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • input: T[]

      The input array.

    • from: number

      The index of the element to swap from.

    • to: number

      The index of the element to swap to.

    Returns T[]

    The modified array with swapped elements.

    Throws

    Will throw an error if 'from' or 'to' is not a valid index in the array.

    Example

    const arr = [1, 2, 3, 4, 5]
    arrSwap(arr, 1, 3) //=> [1, 4, 3, 2, 5]

Generated using TypeDoc