Index of the first occurrence of ch in str
var j = nextOccurrence ( str , n , 0 , ch ) ; for ( var i = 0 ; i < n ; i ++ ) { while ( j !== - 1 && j < i ) { j = nextOccurrence ( str , n , j + 1 , ch ) ; }