rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
24 lines (22 loc) • 508 B
text/typescript
/**
* @public
* Like `Array.map`.
* @remarks
* Has more consistent performance characteristics cross platform than the built in `Array.map`
*
* See {@link arrayMap}.
*/
export function arrayMap<TItem, TMapped>
(
items: ArrayLike<TItem>,
callback: (item: TItem, index: number) => TMapped
)
: TMapped[]
{
const mapped = new Array<TMapped>(items.length);
for (let i = 0, iEnd = items.length; i < iEnd; ++i)
{
mapped[i] = callback(items[i], i);
}
return mapped;
}