Function set

  • Negative indices count backwards from the end of the array. If index is fractional or otherwise invalid, returns a shallow copy of the array.

    Example

    import * as A from "flurp/array";

    const firstToTen = A.set(0, 10);
    firstToTen([3, 4, 5, 6]); // [10, 4, 5, 6]

    const lastToTen = A.set(-1, 10);
    lastToTen([3, 4, 5, 6]); // [3, 4, 5, 10]

    Type Parameters

    • T

    Parameters

    • index: number

      the index at which to update

    • newVal: T

      the new value of the element

    Returns ((arr: readonly T[]) => T[])

      • (arr: readonly T[]): T[]
      • Parameters

        • arr: readonly T[]

        Returns T[]