Count subsequence of length three in a given string | Function to find number of occurrences of a subsequence of length three in a string ; Variable to store no of occurrences ; Loop to find first character ; Loop to find 2 nd character ; Loop to find 3 rd character ; Increment count if subsequence is found ; Driver code
function findOccurrences ( str1 , substr1 ) { let counter = 0 ; for ( let i = 0 ; i < str1 . length ; i ++ ) { if ( str1 [ i ] == substr1 [ 0 ] ) { for ( let j = i + 1 ; j < str1 . length ; j ++ ) { if ( str1 [ j ] == substr1 [ 1 ] ) { for ( let k = j + 1 ; k < str1 . length ; k ++ ) { if ( str1 [ k ] == substr1 [ 2 ] ) counter ++ ; } } } } } return counter ; } let str1 = " " ; let substr1 = " " ; document . write ( findOccurrences ( str1 , substr1 ) ) ;