Created
March 27, 2022 11:48
-
-
Save ramthenmala/277da9e60a4b03c144cee23c2040793b 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 a string using reverse Method | |
function reverseStringMtd(str) { | |
return str | |
.split('') | |
.reverse() | |
.join('') | |
} | |
// Reverse a String using for Loop Method | |
function reverseLoopMtd(strChar) { | |
let res = ''; | |
for(let i = 0; i < strChar.length ; i++){ | |
const char = strChar[i] | |
res = char + res | |
} | |
return res; | |
} | |
// Reverse a String using Reduce Method | |
function reverseStrReduceMtd(str) { | |
return str.split('').reduce((output, char) => { | |
output = char + output | |
return output | |
},'') | |
} | |
reverseStrReduceMtd('almirah') | |
reverseLoopMtd('almirah'); | |
reverseStringMtd('almirah'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment