Skip to content

Instantly share code, notes, and snippets.

@ramthenmala
Created March 27, 2022 11:48
Show Gist options
  • Save ramthenmala/277da9e60a4b03c144cee23c2040793b to your computer and use it in GitHub Desktop.
Save ramthenmala/277da9e60a4b03c144cee23c2040793b to your computer and use it in GitHub Desktop.
// 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