mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
70 lines
1.8 KiB
Markdown
70 lines
1.8 KiB
Markdown
---
|
|
id: 69f35a5bb823ed620fcb7cbd
|
|
title: "Challenge 284: I Before E"
|
|
challengeType: 28
|
|
dashedName: 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"`.
|
|
|
|
```js
|
|
assert.equal(iBeforeE("beleive"), "believe");
|
|
```
|
|
|
|
`iBeforeE("recieve")` should return `"receive"`.
|
|
|
|
```js
|
|
assert.equal(iBeforeE("recieve"), "receive");
|
|
```
|
|
|
|
`iBeforeE("we recieved a breif")` should return `"we received a brief"`.
|
|
|
|
```js
|
|
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"`.
|
|
|
|
```js
|
|
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"`.
|
|
|
|
```js
|
|
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--
|
|
|
|
```js
|
|
function iBeforeE(sentence) {
|
|
|
|
return sentence;
|
|
}
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function iBeforeE(sentence) {
|
|
return sentence.split(' ').map(word => {
|
|
word = word.replace(/([^c])ei/g, '$1ie');
|
|
word = word.replace(/cie/g, 'cei');
|
|
return word;
|
|
}).join(' ');
|
|
}
|
|
```
|