面试题答案
一键面试function transformArray<T>(arr: T[]): T[] {
if (typeof arr[0] ==='string') {
return arr.map((item: string) => item.toUpperCase()) as T[];
} else if (typeof arr[0] === 'number') {
return arr.map((item: number) => item * 2) as T[];
}
return arr;
}