← Back to challenges

Muddled Middles

JavaScriptHardloopsstrings

Instructions

Given a sentence of all lowercase words, reverse all the letters in each word, but leave the first and last letters as they are.

Examples

mixMiddle("the quick brown fox jumps high") ➞ "the qciuk bworn fox jpmus hgih"

mixMiddle("this sentence is quite muddled") ➞ "tihs scnetnee is qtiue melddud"

mixMiddle("buying a first-class ticket") ➞ "bniyug a fsalc-tsris tekcit"

Notes

  • Treat hyphenated words like one word (example #3).
  • Notice how one, two and three-letter words remain unchanged!
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.