Encoding a word into Pig Latin | js program to encode a word to a Pig Latin . ; the index of the first vowel is stored . ; Pig Latin is possible only if vowels is present ; Take all characters after index ( including index ) . Append all characters which are before index . Finally append " ay " ; Driver code
function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function pigLatin ( s ) { let len = s . length ; let index = - 1 ; for ( let i = 0 ; i < len ; i ++ ) { if ( isVowel ( s [ i ] ) ) { index = i ; break ; } } if ( index == - 1 ) return " " ; return s . substring ( index ) + s . substring ( 0 , index ) + " " ; } str = pigLatin ( " " ) ; if ( str == " " ) document . write ( " " + " " + " " ) ; else document . write ( str ) ;