If I have an array of 10 elements, where some are children of others, how can I rearrange this array so that the top parents come first and the deepest children come last?
[
input,
select,
radio,
div (which contains some form elements in the array),
h2,
div (which contains the h2 in the array),
form,
textarea,
a,
span
]
In this scenario, the form element might be the highest-level parent, but I'm seeking a solution to order them without any prior knowledge of their parent-child relationships.