Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.3 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
aa7697ea2477d1316795783b 儿童黑话 5 16039 pig-latin

--description--

儿童黑话,也叫 Pig Latin是一种英语语言游戏。规则如下

- 如果单词以辅音开头,就把第一个辅音字母或第一组辅音簇移到单词的结尾,并在后面加上 "ay"。

- 如果单词以元音开头,只需要在结尾加上 "way"。

在英语中,字母 a、e、i、o、u 为元音,其余的字母均为辅音。辅音簇的意思是连续的多个辅音字母。

--instructions--

请把传入的字符串根据上述规则翻译成儿童黑话并返回结果。输入的字符串一定是一个小写的英文单词。

--hints--

translatePigLatin("california") 应返回 "aliforniacay"。

assert.deepEqual(translatePigLatin('california'), 'aliforniacay');

translatePigLatin("paragraphs") 应返回 "aragraphspay"。

assert.deepEqual(translatePigLatin('paragraphs'), 'aragraphspay');

translatePigLatin("glove") 应返回 "oveglay"。

assert.deepEqual(translatePigLatin('glove'), 'oveglay');

translatePigLatin("algorithm") 应返回 "algorithmway"。

assert.deepEqual(translatePigLatin('algorithm'), 'algorithmway');

translatePigLatin("eight") 应返回 "eightway"。

assert.deepEqual(translatePigLatin('eight'), 'eightway');

Should handle words where the first vowel comes in the middle of the word. translatePigLatin("schwartz") 应返回 "artzschway"。

assert.deepEqual(translatePigLatin('schwartz'), 'artzschway');

应可以处理不含元音的单词,translatePigLatin("rhythm") 应返回 "rhythmay"。

assert.deepEqual(translatePigLatin('rhythm'), 'rhythmay');

--seed--

--seed-contents--

function translatePigLatin(str) {
  return str;
}

translatePigLatin("consonant");

--solutions--

function translatePigLatin(str) {
  if (isVowel(str.charAt(0))) return str + "way";
  var front = [];
  str = str.split('');
  while (str.length && !isVowel(str[0])) {
    front.push(str.shift());
  }
  return [].concat(str, front).join('') + 'ay';
}

function isVowel(c) {
  return ['a', 'e', 'i', 'o', 'u'].indexOf(c.toLowerCase()) !== -1;
}