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
14 lines (13 loc) • 583 B
TypeScript
/**
* Gets an item from an array based on a mapped index.
* @param index The index of the item to get.
* @param array The array to get the item from.
* @param indexMapFn A function that maps the index to a new index.
* @returns The item at the mapped index in the array.
* @example
* const array = ['a', 'b', 'c', 'd', 'e']
* const indexMapFn = (index, length) => (index * 2) % length
* getItem(2, array, indexMapFn)
* // Returns 'e'
*/
export declare const getItem: <T>(index: number, array: T[], indexMapFn: (index: number, length: number) => number) => T;