Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69f35a5bb823ed620fcb7cbd.md
T

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(' ');
}