Smallest String Starting From Leaf Leetcode Javascript Question