Feedback on pigLatin function code


Hi everyone, I just finished the exercises in fundamentals 5 and was looking for some feedback on the pigLatin function. The provided solution looks much different than mine despite them both achieving the same goal. So I was wondering if my code is okay or if I should try to make it more like the “official” solution. The biggest red flag to me about my current code is the flustercluck of a regex that I have. Am I right in assuming that good code should simplify regex’s as much as possible?

function translate(input) {
	const ending = 'ay';
	const consoTest = /^[^aieou]+[q][u]|^[q][u]|^[^aieou]+/gi;
    let singleWords = input.split(' ');
	return => {
    	if (word.toString().search(consoTest) < 0) {
			return word.concat(ending);
        } else if (word.toString().search(consoTest) >= 0 ) {
			return word
				.replace(consoTest, '');
		.join(' ')


If it works then that’s ok. Sometimes regex is complicated but you’ve done the right thing in wrapping it up in a variable. You could consider a better name for the variable perhaps.