← Back to challenges

First Letter Shift

JavaScriptHardstringsloops

Instructions

Given a sentence, create a function which shifts the first letter of each word to the next word in the sentence (shifting right).

Examples

shiftSentence("create a function") ➞ "freate c aunction"

shiftSentence("it should shift the sentence") ➞ "st ihould shift she tentence"

shiftSentence("the output is not very legible") ➞ "lhe tutput os iot nery vegible"

shiftSentence("innokodakademija") ➞ "innokodakademija"

Notes

  • The last word shifts its first letter to the first word in the sentence.
  • All sentences will be given in lowercase.
  • Note how single words remain untouched (example #4).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.