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
69f35a5bb823ed620fcb7cbd Challenge 284: I Before E 28 challenge-284

--description--

Given a word or sentence, return a corrected version where every word follows the "I before E except after C" rule.

  • If a word contains "ei" not preceded by "c", replace it with "ie".
  • If a word contains "ie" preceded by "c", replace it with "ei".
  • All other words are left unchanged.

--hints--

iBeforeE("beleive") should return "believe".

assert.equal(iBeforeE("beleive"), "believe");

iBeforeE("recieve") should return "receive".

assert.equal(iBeforeE("recieve"), "receive");

iBeforeE("we recieved a breif") should return "we received a brief".

assert.equal(iBeforeE("we recieved a breif"), "we received a brief");

iBeforeE("she beleived the friendly niece could percieve the greif") should return "she believed the friendly niece could perceive the grief".

assert.equal(iBeforeE("she beleived the friendly niece could percieve the greif"), "she believed the friendly niece could perceive the grief");

iBeforeE("we recieved relief after the theif gave us a breif piece of feirce deceit") should return "we received relief after the thief gave us a brief piece of fierce deceit".

assert.equal(iBeforeE("we recieved relief after the theif gave us a breif piece of feirce deceit"), "we received relief after the thief gave us a brief piece of fierce deceit");

--seed--

--seed-contents--

function iBeforeE(sentence) {

  return sentence;
}

--solutions--

function iBeforeE(sentence) {
  return sentence.split(' ').map(word => {
    word = word.replace(/([^c])ei/g, '$1ie');
    word = word.replace(/cie/g, 'cei');
    return word;
  }).join(' ');
}