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.0 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
aa7697ea2477d1316795783b Pig Latin 5 16039 pig-latin

--description--

Pig Latin is a way of altering English Words. The rules are as follows:

- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add "ay" to it.

- If a word begins with a vowel, just add "way" at the end.

--instructions--

Translate the provided string to Pig Latin. Input strings are guaranteed to be English words in all lowercase.

--hints--

translatePigLatin("california") should return "aliforniacay".

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

translatePigLatin("paragraphs") should return "aragraphspay".

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

translatePigLatin("glove") should return "oveglay".

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

translatePigLatin("algorithm") should return "algorithmway".

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

translatePigLatin("eight") should return "eightway".

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

Should handle words where the first vowel comes in the middle of the word. translatePigLatin("schwartz") should return "artzschway".

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

Should handle words without vowels. translatePigLatin("rhythm") should return "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;
}