Function update

  • Applies a transformation to the value of an array at the specified index.

    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";
    import * as N from "flurp/number";

    const doubleFirst = A.update(0, N.multiply(2));
    doubleFirst([3, 4, 5, 6]); // [6, 4, 5, 6]

    const doubleLast = A.update(-1, N.multiply(2));
    doubleLast([3, 4, 5, 6]); // [3, 4, 5, 12]

    Type Parameters

    • T

    Parameters

    • index: number
    • transformation: ((x: T) => T)
        • (x: T): T
        • Parameters

          • x: T

          Returns T

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

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

        • arr: readonly T[]

        Returns T[]