Program to count occurrence of a given character in a string | package whatever do not write package name here ; base case ; ; checking if the first character of the given string is that character or not ; this will count the occurrence of given character in the string from index 1 to the last index of the string ; Driver code
function countinString ( ch , s ) { if ( s . length == 0 ) return 0 ; var count = 0 ; if ( s [ 0 ] == ch ) count ++ ; count += countinString ( ch , s . substring ( 1 ) ) ; return count ; } var str = " " ; var c = ' ' ; document . write ( countinString ( c , str ) ) ;