Last active
September 25, 2024 15:48
-
-
Save allenhwkim/a060441708fcfd6dfe0b776ae3d8fcb3 to your computer and use it in GitHub Desktop.
reverstString(str)
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
function reverseString(str) { | |
return !str ? '' : reverseString(str.substr(1)) + str.charAt(0); | |
} | |
reverseString("hello"); | |
function reverse(str){ | |
for (var i = str.length - 1, s=""; i >= 0; i--) s += str[i]; | |
return s; | |
}; | |
reverse("your string comes here") | |
// split to chunks, 4 characters, and reverse | |
function chunkReverse(str) { | |
return (str.match(/.{1,4}/g) || []).reduce( (acc, el) => acc.push(reverse(el)) && acc, []).join('') | |
} | |
chunkReverse('1234567890') // 4321876509 | |
chunkReverse('4321876509') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment