Created
June 23, 2024 03:31
-
-
Save ksamirdev/58a7ac1010068c87bdd3c9222a9ff101 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 revWithReduce(str: string): string { | |
return str.split("").reduce((acc, curr) => curr + acc, ""); | |
} | |
function revWithLoop(str: string): string { | |
let reversed = ""; | |
for (let i = str.length - 1; i >= 0; i--) { | |
reversed += str.at(i); | |
} | |
return reversed; | |
} | |
function revWithRecursion(str: string): string { | |
if (!str) return ""; | |
return rev(str.substring(1)) + str.charAt(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment