Middle
Implement TypeScript typings for the customMap function, which takes an array of any type and a transformer function that returns another type. The transformer function should accept three arguments (like a callback in Array.map).
sobes.tech AI
Answer from AI
typescript function customMap<T, U>( arr: T[], transformer: (value: T, index: number, array: T[]) => U ): U[] { const result: U[] = []; for (let i = 0; i < arr.length; i++) { result.push(transformer(arr[i], i, arr)); } return result; }
Here, `T` is the type of the elements of the input array, and `U` is the type of the elements of the result. The `transformer` function takes three arguments: the current element, the index, and the original array, and returns an element of type `U`.