Acest bonfire nu mi s-a părut complicat.
function translate(str) { // create an array with vowels // get the first index of a voewl var vowels = /[aeiou]/; var firstVowel = str.search(vowels); var consonants = str.substr(0, firstVowel); var suffix = consonants + 'ay'; console.log(consonants); if ( firstVowel > 0 ) { str = str.substr(firstVowel) + suffix; } else { str = str + 'way'; } // str = str.substr(first) + suffix return str; } translate("consonant");