Created
October 3, 2017 20:08
-
-
Save baribadamshin/f2068e63a40cada7889acda5c0203a3d to your computer and use it in GitHub Desktop.
This file contains 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 revertWordInString(str) { | |
if (str.trim().length === 0) { | |
throw 'err'; | |
} | |
return str | |
.split(/\s/) | |
.map(str => str.length | |
? str.split('').reverse().join('') | |
: str) | |
.join(' '); | |
} | |
console.log(revertWordInString('one two three four five')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment