面试题答案
一键面试function combine(a: string, b: string): string;
function combine(a: number, b: number): number;
function combine<T>(arr: T[], item: T): T[];
function combine(a: any, b: any): any {
if (typeof a ==='string' && typeof b ==='string') {
return a + b;
} else if (typeof a === 'number' && typeof b === 'number') {
return a + b;
} else if (Array.isArray(a) && a.length > 0 && a[0] === b) {
return [...a, b];
}
return null;
}