Created
April 13, 2021 11:04
-
-
Save shoaibmehedi7/146b79331d456a23da83bd57cc2491b5 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
// reverse using basic functions | |
function reverse(string) { | |
return string.split("").reverse().join(""); | |
} | |
console.log(reverse('shoaib')); | |
// reverse using loop | |
function reverse(string) { | |
var newString = ""; | |
for (var i = string.length - 1; i >= 0; i--) { | |
newString += string[i]; | |
} | |
return newString; | |
} | |
console.log(reverse('shoaib')); | |
// reverse using recursion function | |
function reverse(string) { | |
if (string === "") | |
return ""; | |
else | |
return reverse(string.substr(1)) + string.charAt(0); | |
} | |
console.log(reverse('shoaib')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment