Setting child index of unknown child

I want to bring a display object to a specific position knowing only the child itself and the uppermost container whose indexes will have to be changed. Here’s the setup:

container
- child1
-- subchild1
-- subchild2
- child2
-- subchild3
-- subchild4
-- subchild5
[...]
- child3
-- subchild23
-- subchild24

I know that container contains an interesting child nested inside itself. Let’s call it subchild15, but it actually can be even more nested.

How to I make sure that subchild15 appears (via child index) between *child2 *and child1 without knowing it’s closest parent to container?

I can only think of the following method:

function getClosestChildThatContains(container, nestedChild) {
    for (var i=0; i < container.numChildren; i++) {
        var child = container.getChildAt(i)
        if (child == nestedChild)
            return child
        else if (child.contains(nestedChild))
            return getClosestChildThatContains(child, nestedChild)
    }
}
trace(getClosestChildThatContains(container, subchild15))

But it looks painfully complex and slow. Speed is not really a problem in this case, the function will be called only once every few seconds (for now), but I was wondering if there is anything more elegant to do in this case.