Intermediate Algorithm Scripting: Pig Latin; word without vowel

function translatePigLatin(str) {
	str = str.split("")
        let vowels = 'aeiou'
	let index= str.findIndex(value => vowels.includes(value))
	if(index == 0) {
		return str.splice(index).concat(['w', 'a', 'y']).join('')
	return str.splice(index).concat(str, ['a', 'y']).join('')


In the instructions nothing mentions, what should the function return if a word without vowel is passed and my code pass all the test except last one…

If there is no vowel then the consonant cluster is the whole word and you just add ay at the end

Anyway, check your last splice, you have a typo there

1 Like

yaa I correct my last splice but what should the function should return if there is no vowels in the word e.g ‘xyz’

There is something you don’t understand in the first sentence of my last post?

Oh I got it you said this :

else if(index === -1) {
    return str.concat(['a', 'y']).join('')

it returns xyzay

Okay - it seems to me that this should work with words without vowels:

pigLatin = str.replace(/([^aeiouy]+)(.*)/g, "$2$1ay");

Can anybody see what’s wrong?

y is not a vowel - can’t check the rest now, but let us know if wth that change it works

Thank you so much!

I would never have thought of this. In Denmark, where I reside, ‘y’ is a vowel, but I see that this is not the case for English. Thanks. :slight_smile: