0

I have two queries in this issue. I am writing a PigLatin code in JavaScript in which the following words are supposed to return the following responses:

"computer" == "omputercay"
"think" == "inkthay"
"algorithm" == "algorithmway"
"office" == "officeway"
"Computer" == "Omputercay"
"Science!" == "Iencescay!"

However my code returns the following responses for the last two words: "omputerCay" and "ience!Scay". The first query I have is to find out how to capitalise the first letter of omputerCay and make the "C" lowercase. The second is to do the same thing but also move the "!" to the end of the word.

The suggested articles did not help move the "!" to the end of the word.

function pigLatin(str) {

let vowels = ['a', 'e', 'i', 'o', 'u'];
let newStr = "";

if (vowels.indexOf(str[0]) > -1) {
  newStr = str + "way";
  return newStr;
} else {
  let firstMatch = str.match(/[aeiou]/g) || 0;
  let vowel = str.indexOf(firstMatch[0]);
  newStr = str.substring(vowel) + str.substring(0, vowel) + "ay";
  return newStr;
}}
  • Maybe look into `.toUpperCase` and `.toLowerCase`? – Sumner Evans Jan 11 '21 at 00:01
  • 2
    I don't think the apache-pig tag belongs on this question. Does it have anything to do with Apache Pig? – wensveen Jan 11 '21 at 00:07
  • 1
    This should be helpful for your capitalization issue: https://stackoverflow.com/a/35782871/5774952 – Zac Anger Jan 11 '21 at 00:11
  • 1
    Does this answer your question? [Convert camelCaseText to Sentence Case Text](https://stackoverflow.com/questions/7225407/convert-camelcasetext-to-sentence-case-text) – Sam Jan 11 '21 at 00:25
  • Hope one of those duplicates answers your question! If not, edit your post to say why they don't work. – Sam Jan 11 '21 at 00:29

0 Answers0