So for my cit class I have to write a pig Latin converter program and I\'m really confused on how to use arrays and strings together. The rules for the conversion are simpl
Your friends are the string function .split
, and the array functions .join
and .slice
and .concat
.
warning: Below is a complete solution you can refer to once you have finished or spent too much time.
function letters(word) {
return word.split('')
}
function pigLatinizeWord(word) {
var chars = letters(word);
return chars.slice(1).join('') + chars[0] + 'ay';
}
function pigLatinizeSentence(sentence) {
return sentence.replace(/\w+/g, pigLatinizeWord)
}
Demo:
> pigLatinizeSentence('This, is a test!')
"hisTay, siay aay esttay!"