Find total no of collisions taking place between the balls in which initial direction of each ball is given | Function to count no of collision ; length of the string ; Driver code
function count ( s ) { let N , i , cnt = 0 , ans = 0 ; N = s . length ; for ( i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' ' ) cnt ++ ; if ( s [ i ] == ' ' ) ans += cnt ; } return ans ; } let s = " " ; document . write ( count ( s ) ) ;