Created
November 26, 2018 14:28
-
-
Save ragmha/f680077df74e8f7e47b3c486b9222fdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverse(str: string): string; | |
function reverse<T>(arr: T[]): T[]; | |
function reverse<T>(stringOrArray: string | T[]): string | T[] { | |
if (typeof stringOrArray === "string") { | |
return stringOrArray | |
.split("") | |
.reverse() | |
.join(""); | |
} | |
return stringOrArray.slice().reverse(); | |
} | |
let str = reverse("Pepperoni"); | |
console.log(`String reversed ${str}`); | |
let arr = reverse(["lol", "what", "hahhue"]); | |
console.log(`Arr reversed ${arr}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment