I've been searching the web and can't find an answer to this. How can you find the leftmost/rightmost nodes of a tree with an arbitrary number of child nodes per node?

In a binary search tree this would presumably be the smallest and the greatest values in the tree. How would this work when any node can have any number of child nodes?

Only solution that comes to mind is something like, in JS syntax:

and about the same for rightmost. Is simply stepping down through the tree not enough? What language/structure are you exactly using?