Function to count the frequency of node value present in the tree
function frequencyCounts ( map , root ) { if ( root == null ) return ; if ( map . has ( root . key ) ) map . set ( root . key , map . get ( root . key ) + 1 ) ; else map . set ( root . key , 1 ) ; frequencyCounts ( map , root . left ) ; frequencyCounts ( map , root . right ) ; }