param string function reverse ( string ) ; param array function reverse < T > ( array ) ; function reverse ( stringOrArray ) { return typeof stringOrArray === "string" ? [ ... stringOrArray ] . reverse ( ) . join ( "" ) : stringOrArray . slice ( ) . reverse ( ) ; } const reversedString = reverse ( "TypeScript" ) ; const reversedArray = reverse ( [ 4 , 8 , 15 , 16 , 23 , 42 ] ) ;