Skip to content

Instantly share code, notes, and snippets.

@baribadamshin
Created October 3, 2017 20:08
Show Gist options
  • Save baribadamshin/f2068e63a40cada7889acda5c0203a3d to your computer and use it in GitHub Desktop.
Save baribadamshin/f2068e63a40cada7889acda5c0203a3d to your computer and use it in GitHub Desktop.
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