Function replaceSlice

  • Replaces the elements from startIndex to (but not including) endIndex with replacement. Returns a shallow copy without replacement if startIndex >= endIndex or if one or both indices is not an integer.

    Negative indices count backwards from the end of the array.

    Example

    import * as A from "flurp/array";
    import * as L from "flurp/logic";
    import * as N from "flurp/number";

    const replaceSecondAndThird = A.replaceSlice(1, 3, [10, 11, 12]);
    replaceSecondAndThird([1, 2, 3, 4, 5]); // [1, 10, 11, 12, 4, 5]

    const replaceSecondToLast = A.replaceSlice(-2, -1, [10, 11, 12]);
    replaceSecondToLast([1, 2, 3, 4, 5]); // [1, 2, 3, 10, 11, 12, 5];

    Type Parameters

    • T

    Parameters

    • startIndex: number
    • endIndex: number
    • replacement: T[]

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

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

        • arr: readonly T[]

        Returns T[]