UNPKG

data-fns

Version:

This library provides utility functions for working with array data that are useful in many contexts, including creative coding. It offers generic functions that perform common operations such as offsetting an array, generating an array based on a callbac

13 lines (12 loc) 525 B
/** * Maps an item in an array at a specified index to a new value. * @param array The array to map the item in. * @param index The index of the item to map. * @param mapFn A function that maps the item to a new value. * @returns A new array with the mapped item. * @example * const originalArray = [1, 2, 3, 4, 5] * const mappedArray = mapAt(originalArray, 2, (item) => item * 2) * // Returns [1, 2, 6, 4, 5] */ export declare const mapAt: <T>(array: T[], index: number, mapFn: (item: T) => T) => T[];