Created
January 13, 2018 07:36
-
-
Save pankajladhar/30e71ca7a0e3d602cac1ef1c48341697 to your computer and use it in GitHub Desktop.
Reverse a string
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
/* | |
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