Skip to content

Instantly share code, notes, and snippets.

@pankajladhar
Created January 13, 2018 07:36
Show Gist options
  • Save pankajladhar/30e71ca7a0e3d602cac1ef1c48341697 to your computer and use it in GitHub Desktop.
Save pankajladhar/30e71ca7a0e3d602cac1ef1c48341697 to your computer and use it in GitHub Desktop.
Reverse a string
/*
ReverseString(str) take the str parameter being passed and return the string in reversed order.
For example: if the input string is "Hello World and Coders"
then your program should return the string sredoC dna dlroW olleH.
*/
const ReverseString = (str) => {
let reversedString = "";
for (let i = str.length - 1 ; i >= 0; i--) {
reversedString = reversedString + str[i]
}
return reversedString
}
const Reverse_builtIn = (str) =>{
return str.split("").reverse().join("");
}
console.log(ReverseString("Hello World and Coders")) // sredoC dna dlroW olleH
console.log(Reverse_builtIn("Hello World and Coders")) //sredoC dna dlroW olleH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment