Count strings from given array having all characters appearing in a given string | Function to count the number of strings from an array having all characters appearing in the string S ; Initialize a set to store all distinct characters of string S ; Traverse over string S ; Insert characters into the Set ; Stores the required count ; Traverse the array ; Traverse over string arr [ i ] ; Check if character in arr [ i ] [ j ] is present in the string S or not ; Increment the count if all the characters of arr [ i ] are present in the string S ; Finally , print the count ; Driver code
function countStrings ( S , list ) { let valid = new Set ( ) ; for ( let x of S ) { valid . add ( x ) ; } let cnt = 0 ; for ( let i = 0 ; i < list . length ; i ++ ) { let j = 0 ; for ( j = 0 ; j < list [ i ] . length ; j ++ ) { if ( valid . has ( list [ i ] [ j ] ) ) continue ; else break ; } if ( j == list [ i ] . length ) cnt ++ ; } return cnt ; } let arr = [ " " , " " , " " , " " ] ; let S = " " ; document . write ( countStrings ( S , arr ) + " " ) ;