Count consonants in a string ( Iterative and recursive methods ) | Function to check for consonant ; To handle lower case ; To count total number of consonants from 0 to n - 1 ; Driver code
function isConsonant ( ch ) { ch = ch . toUpperCase ( ) ; return ( ! ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) && ch . charCodeAt ( 0 ) >= 65 && ch . charCodeAt ( 0 ) <= 90 ) ; } function totalConsonants ( str , n ) { if ( n == 1 ) return isConsonant ( str [ 0 ] ) ; return totalConsonants ( str , n - 1 ) + isConsonant ( str [ n - 1 ] ) ; } var str = " " ; document . write ( totalConsonants ( str , str . length ) ) ;