Modify string by removing vowels in between two consonants | Function to check if the character x is a vowel or not ; Returns the updated string formed after removing all the Sandwiched Vowels from the given string ; string to store the Updated String after removing the Sandwiched Vowels ; traverse the string from left to right ; if the current character is the first or the last character of the string then , this needs to be appended to the updatedString , since the corner alphabet irrespective of it being a vowel or a consonant , is never ' Sandwiched ' ; Check if the current character of the string is a vowel and both the previous and the next characters are consonants , if so then this is a sandwiched vowel , thus is ignored and not appended to the updated string ; if this character is not a sandwiched Vowel append it to the updated String ; Driver Code ; Remove all the Sandwitched Vowels
function isVowel ( x ) { if ( x === " " x === " " x === " " x === " " x === " " ) return true ; else return false ; } function updateSandwichedVowels ( a ) { var n = a . length ; var updatedString = " " ; for ( var i = 0 ; i < n ; i ++ ) { if ( i === 0 i === n - 1 ) { updatedString += a [ i ] ; continue ; } if ( isVowel ( a [ i ] ) === true && isVowel ( a [ i - 1 ] ) === false && isVowel ( a [ i + 1 ] ) === false ) { continue ; } updatedString += a [ i ] ; } return updatedString ; } var str = " " ; var updatedString = updateSandwichedVowels ( str ) ; document . write ( updatedString ) ;