maintain an index to count number of nodes processed so far
count = 0 ; let res = kthSmallest ( root , k ) ; if ( res == null ) document . write ( " " + " " ) ; else document . write ( " " + " " + res . data ) ; }