Created
September 25, 2019 03:31
-
-
Save jerolan/e4e9205b69016c89cb41860ec04a5d84 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
/** | |
* First Reverse | |
* Have the function FirstReverse(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. | |
* | |
* Test Cases | |
* > firstReverse "Hello World and Coders" | |
* "sredoC dna dlroW olleH" | |
* | |
* > firstReverse "coderbyte" | |
* "etybredoc" | |
*/ | |
function firstReverse(str) { | |
return str | |
.split("") | |
.reverse() | |
.join(""); | |
} |
Another one is
function firstReverse(str) {
if (typeof str != String) {str += ''}
var str1 = [], str2 = [], i = 0;
while (i < str.length) {
str1.push(str.substr(i++,1) );
}
for (i in str1) {
str2.unshift(str1[i]);
}
return String(str2.join('') );
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Other solution could be