Pig Latin algorithm.. Help needed!

function translatePigLatin(str) {
  var regexp=/[a,e,i,o,u]/gi; 
  var answer='';
  var a=str.split('');
  var matches=str.match(regexp);
  return answer;
 /* if(str[0].match(regexp)){
  return answer;


this is my code the second if statement works. i want to know why is my first if statement not working.

var matches = str.match(regexp) which is [a,a,a]
str[0]==matches eg str[0]=p … matches is a array
str[0]===matches[0] false as str is p matches[0] is a
str[1] ===matches[0] true as str[1] is a

but regexp=[a,e,i,o,u]… then why matches only equal to a?

as there are only…a… in paragraphs … for words containing eiou it will pick them up. but your are using a if statement to check just the first letter of the string against a array. you need to use a loop to check each letter of the string against each part of the array eg check string[i] === matches[i] or use filter()

1 Like

Thanx. U explained deeply. can you help me with the intermediate algorithm Boo who.

sorry havent reached that far yet

It’s okay. Maybe You will need me.:grinning: