Files
freeCodeCamp/curriculum/challenges/russian/08-coding-interview-prep/rosetta-code/i-before-e-except-after-c.russian.md

3.1 KiB
Raw Blame History

title, id, challengeType, forumTopicId, localeTitle
title id challengeType forumTopicId localeTitle
I before E except after C 5a23c84252665b21eecc7eb0 5 302288 I до E, за исключением C

Description

Фраза «I до E, за исключением C» - широко известная мнемоника, которая должна помочь при написании английских слов. Используя предоставленные слова, проверьте, являются ли два подкласса фразы правдоподобными:
  1. «Я до E, когда не предшествует C».
  2. «E до I, когда предшествует C».
Если обе подфразы правдоподобны, то исходную фразу можно назвать правдоподобной. Напишите функцию, которая принимает слово и проверяет, соответствует ли это слово этому правилу. Функция должна возвращать true, если она соответствует правилу, в противном случае false.

Instructions

Write a function that accepts a word and check if the word follows this rule. The function should return true if the word follows the rule and false if it does not.

Tests

tests:
  - text: <code>IBeforeExceptC</code> should be a function.
    testString: assert(typeof IBeforeExceptC=='function');
  - text: <code>IBeforeExceptC("receive")</code> should return a boolean.
    testString: assert(typeof IBeforeExceptC("receive")=='boolean');
  - text: <code>IBeforeExceptC("receive")</code> should return <code>true</code>.
    testString: assert.equal(IBeforeExceptC("receive"),true);
  - text: <code>IBeforeExceptC("science")</code> should return <code>false</code>.
    testString: assert.equal(IBeforeExceptC("science"),false);
  - text: <code>IBeforeExceptC("imperceivable")</code> should return <code>true</code>.
    testString: assert.equal(IBeforeExceptC("imperceivable"),true);
  - text: <code>IBeforeExceptC("inconceivable")</code> should return <code>true</code>.
    testString: assert.equal(IBeforeExceptC("inconceivable"),true);
  - text: <code>IBeforeExceptC("insufficient")</code> should return <code>false</code>.
    testString: assert.equal(IBeforeExceptC("insufficient"),false);
  - text: <code>IBeforeExceptC("omniscient")</code> should return <code>false</code>.
    testString: assert.equal(IBeforeExceptC("omniscient"),false);

Challenge Seed

function IBeforeExceptC(word) {
  // Good luck!
}

Solution

function IBeforeExceptC(word)
{
    if(word.indexOf("c")==-1 && word.indexOf("ie")!=-1)
        return true;
    else if(word.indexOf("cei")!=-1)
        return true;
    return false;
}