Can not pass intermediate algorithm scripting pig latin

function translatePigLatin(str) {
  let arr  =str.split("");
  console.log(arr);
  let arr1 = str.search(/a|i|u|y|e|o/i);
  console.log(arr1);
  if (arr1 == 0){
    return arr.join("")+"way";
  } else { 
  let arrSplice = arr.splice(0,arr1 );
   console.log(arrSplice);
console.log(arr);
let strLat = arr.concat(arrSplice).join("");

console.log(strLat+"ay");
  return strLat+"ay";}
}

translatePigLatin("california");

Can not pass :Should handle words without vowels.
Who can explain what is wrong

I don’t know if it is the only issue, but you shouldn’t consider y as a vowel

Can you show the example how to do ?

I would personally use test() to test my strings: MDN test()
This will simply test a string to see if it matches a regex pattern.

Another tool which will really help you is RegexPal: Regex Pal
This will make it a lot easier for you to see what you regexes are doing without having to run the code.

Your vowel regex should only include vowels as mentioned by @ilenia. So your vowel regex should be /[aeiou]/

In order to find the position of a vowel it might useful for you to use a for loop. This will allow you to test each character of a string against your regex, systematically: MDN For Of Loop

The example I have included below demonstrates how a for of loop can iterate over a string and return the index of the first vowel:

  const regex=/[aeiou]/;
  for(let char of str){
    if(regex.test(char)){
      return str.indexOf(char);
    }
  }

As you can see, I have removed the i identifier as the task states all words will be lowercase anyway. What the above loop is saying is as follows:

For every character char in the string str test is against regex and, if it matches return the index.

Hope this sets you on your way

Thank you ) It works

You don’t need an example - You shouldn’t consider y as a vowel - remove y from here

Thank you ) I understand