Count of substrings of a string containing another given string as a substring | Function to store all substrings of S ; Stores the substrings of S ; Pick start point in outer loop and lengths of different strings for a given starting point ; Return the array containing substrings of S ; Function to check if a string is present in another string ; Check if target is in the string str or not ; Function to count the substring of S containing T in it as substring ; Store all substrings of S in the array v [ ] ; Store required count of substrings ; Iterate through all the substrings of S ; If string T is present in the current substring , then increment the ans ; Print the answer ; Driver code ; Function Call
function subString ( s , n ) { var v = [ ] ; var i , len ; for ( i = 0 ; i < n ; i ++ ) { for ( len = 1 ; len <= n - i ; len ++ ) { var find = s . substr ( i , len ) ; v . push ( find ) ; } } return v ; } function IsPresent ( str , target ) { if ( str . includes ( target ) ) { return 1 ; } return - 1 ; } function countSubstrings ( S , T ) { var v = subString ( S , S . length ) ; var ans = 0 ; var i ; for ( i = 0 ; i < v . length ; i ++ ) { if ( IsPresent ( v [ i ] , T ) != - 1 ) { ans ++ ; } } document . write ( ans ) ; } var S = " " ; var T = " " ; countSubstrings ( S , T ) ;