Applies a transformation to the value of an array at the specified index.
transformation
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.
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]
Applies a
transformation
to the value of an array at the specifiedindex
.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