text: Replace every consonant sequence with its length in the given string | Function to return the converted string after replacing every consonant sequence with its length ; To store the resultant string ; Checking each character for consonant sequence ; Count the length of consonants sequence ; Add the length in the string ; Add the vowel ; Check for the last consonant sequence in the string ; Return the resultant string ; Driver code
code: function replaceConsonants ( str ) { var res = " " ; var i = 0 , count = 0 ; while ( i < str . length ) { if ( str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " && str [ i ] !== " " ) { i ++ ; count ++ ; } else { if ( count > 0 ) res += count . toString ( ) ; res += str [ i ] ; i ++ ; count = 0 ; } } if ( count > 0 ) res += count . toString ( ) ; return res ; } var str = " " ; document . write ( replaceConsonants ( str ) ) ;