Junior — Senior
Creating your own generic map functionality
livecode
Task condition
Develop your own implementation of the map function using generics. The function should accept two arguments: an array of elements of any type and a callback function that transforms each element. The result should return a new collection containing the values obtained after applying the callback to all elements of the original array.
function myMap<T, U>(source: T[], transform: (item: T) => U): U[] {
// implementation
}
Requirements:
- The function must be fully type-safe.
- Do not modify the original array.
- Ensure correct operation with empty arrays and various data types.
- Do not use the built-in
Array.prototype.map.