← Back to challenges

Correct My Sentence

JavaScriptHardsortingvalidationlanguage_fundamentalsconditionsregex

Instructions

Mubashir is not so good with the English language. He needs your help to correct his sentences.

  1. Start each sentence with an uppercase alphabet.
  2. For every uppercase letter (other than the first alphabet), you have to place a fullstop(.) followed by an empty space.
  3. There must be only one space between the words and sentences.
  4. Sentence must end with a full stop(.)
  5. Two continuous spaces are not allowed.
correctSentences ("  mubashir loves  innokodakademija  Matt  loves  innokodakademija  ") ➞ "Mubashir loves innokodakademija. Matt loves innokodakademija."

// Remove extra spaces.
// Capitalise first character.
// Dot followed by an empty space before "Matt".
// A dot at the end.

Examples

correctSentences ("  mubashir loves  innokodakademija  Matt  loves  innokodakademija  ") ➞ "Mubashir loves innokodakademija. Matt loves innokodakademija."

correctSentences ("  he is an engineer He sleeps a lot") ➞ "He is an engineer. He sleeps a lot."

correctSentences (" his english is not good Help him     Thank you") ➞ "His english is not good. Help him. Thank you."

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Count Number of Instances