Count array elements whose all distinct digits appear in K | Function to the count of array elements whose distinct digits are a subset of the digits of K ; Stores distinct digits of K ; Iterate over all the digits of K ; Insert current digit into set ; Update K ; Stores the count of array elements whose distinct digits are a subset of the digits of K ; Traverse the array , arr ; Stores current element ; Check if all the digits of arr [ i ] are present in K or not ; Iterate over all the digits of arr [ i ] ; Stores current digit ; If digit not present in the set ; Update flag ; Update no ; If all the digits of arr [ i ] present in set ; Update count ; Driver Code
function noOfValidKbers ( K , arr ) { var set = new Set ( ) ; while ( K != 0 ) { set . add ( K % 10 ) ; K = parseInt ( K / 10 ) ; } var count = 0 ; for ( i = 0 ; i < arr . length ; i ++ ) { var no = arr [ i ] ; var flag = true ; while ( no != 0 ) { var digit = no % 10 ; if ( ! set . has ( digit ) ) { flag = false ; break ; } no = parseInt ( no / 10 ) ; } if ( flag == true ) { count ++ ; } } return count ; } var K = 12 ; var arr = [ 1 , 12 , 1222 , 13 , 2 ] ; document . write ( noOfValidKbers ( K , arr ) ) ;