Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
698a1a73ade5ac0e19180fa5 Challenge 202: Add Punctuation 28 challenge-202

--description--

Given a string of sentences with missing periods, add a period (".") in the following places:

  • Before each space that comes immediately before an uppercase letter
  • And at the end of the string

Return the resulting string.

--hints--

addPunctuation("Hello world") should return "Hello world."

assert.equal(addPunctuation("Hello world"), "Hello world.");

addPunctuation("Hello world It's nice today") should return "Hello world. It's nice today."

assert.equal(addPunctuation("Hello world It's nice today"), "Hello world. It's nice today.");

addPunctuation("JavaScript is great Sometimes") should return "JavaScript is great. Sometimes."

assert.equal(addPunctuation("JavaScript is great Sometimes"), "JavaScript is great. Sometimes.");

addPunctuation("A b c D e F g h I J k L m n o P Q r S t U v w X Y Z") should return "A b c. D e. F g h. I. J k. L m n o. P. Q r. S t. U v w. X. Y. Z."

assert.equal(addPunctuation("A b c D e F g h I J k L m n o P Q r S t U v w X Y Z"), "A b c. D e. F g h. I. J k. L m n o. P. Q r. S t. U v w. X. Y. Z.");

addPunctuation("Wait.. For it") should return "Wait... For it."

assert.equal(addPunctuation("Wait.. For it"), "Wait... For it.");

--seed--

--seed-contents--

function addPunctuation(sentences) {

  return sentences;
}

--solutions--

function addPunctuation(sentences) {
  let result = "";

  for (let i = 0; i < sentences.length; i++) {
    if (sentences[i] === " " && i + 1 < sentences.length && /[A-Z]/.test(sentences[i + 1])) {
      result += ".";
    }
    result += sentences[i];
  }
  result += ".";

  return result;
}