curriculum/challenges/english/blocks/lab-pig-latin/aa7697ea2477d1316795783b.md
Pig Latin is a way of altering English words by following specific transformation rules.
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
translatePigLatin function that accepts one string as argument.ay to it, and return the result.way at the end and return the result.ay at the end and return the result.Note: For the context of this lab, vowels are a, e, i, o, and u. The letter y is not considered a vowel.
You should have a translatePigLatin function.
assert.isFunction(translatePigLatin);
translatePigLatin("california") should return the string aliforniacay.
assert.deepEqual(translatePigLatin('california'), 'aliforniacay');
translatePigLatin("paragraphs") should return the string aragraphspay.
assert.deepEqual(translatePigLatin('paragraphs'), 'aragraphspay');
translatePigLatin("glove") should return the string oveglay.
assert.deepEqual(translatePigLatin('glove'), 'oveglay');
translatePigLatin("algorithm") should return the string algorithmway.
assert.deepEqual(translatePigLatin('algorithm'), 'algorithmway');
translatePigLatin("eight") should return the string eightway.
assert.deepEqual(translatePigLatin('eight'), 'eightway');
Should handle words where the first vowel comes in the middle of the word. translatePigLatin("schwartz") should return the string artzschway.
assert.deepEqual(translatePigLatin('schwartz'), 'artzschway');
Should handle words without vowels. translatePigLatin("rhythm") should return the string rhythmay.
assert.deepEqual(translatePigLatin('rhythm'), 'rhythmay');
function translatePigLatin(str) {
if (isVowel(str.charAt(0))) return str + "way";
let 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;
}