I can’t answer for @pete31, of course. But I can try to illustrate what they meant by “You need to recursively get each subgroup’s childen” in a JavaScript snippet – AppleScript is outside of my comfort zone, but I’m sure you get the gist:
const allChildren = [];
function getChildrenOfGroup(g) {
/* g must be a group. Loop over all its children */
g.children().forEach((c) => {
if (c.type() === "group") {
/* The current child is a group -> call this function again to get all its children */
getChildrenOfGroup(c);
/* if you want to _keep_ all groups, too, add this child to the allChildren list
before calling getChildrenOf Group again */
} else {
/* The current child is no group -> append it to the list of children */
allChildren.push(c);
}
})
}
Now, you can of course write any recursive function non-recursively, so it’s not necessary to do it as I did here.
The idea of a recursive function is that it calls itself until there’s nothing more to act upon. Like here: It calls itself for every group it encounters and only copies the non-groups to a global array (which is probably not a good design choice, but given my comfort zone …).
There’s a bunch of explanations about recursion out there. Wikipedia and your favorite search engine probably tell you more about them than you ever wanted to know.