Find the number of occurrences of a character upto preceding position | Function to find the number of occurrences of a character at position P upto p - 1 ; Return the required count ; Driver code ; Function call
function Occurrence ( s , position ) { let count = 0 ; for ( let i = 0 ; i < position - 1 ; i ++ ) if ( s [ i ] == s [ position - 1 ] ) count ++ ; return count ; } let s = " " ; let p = 9 ; document . write ( Occurrence ( s , p ) ) ;