Traverse through all common element , and pick minimum occurrence from two arrays
let res = 0 ; for ( let x of countA . keys ( ) ) if ( countB . has ( x ) ) res += Math . min ( countB . get ( x ) , countA . get ( x ) ) ;