Skip to content

Instantly share code, notes, and snippets.

@pratyushcrd
Created January 14, 2018 06:59
Show Gist options
  • Save pratyushcrd/e5babd37b54254dc59b4e5d376c9c03e to your computer and use it in GitHub Desktop.
Save pratyushcrd/e5babd37b54254dc59b4e5d376c9c03e to your computer and use it in GitHub Desktop.
// Reverse only the letters of words in a sentence
// A helper function to reverse words
const reverseWord = str => str.split('').reverse().join('')
// Actual function
const reverseLettersInSentence = sentence => sentence
.split(' ')
.map(reverseWord)
.join(' ')
// Execution
reverseLettersInSentence('Hello World')
// Output
"olleH dlroW"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment