Skip to content
Advertisement

Order childs of array

I have this array with parents and their children:

JavaScript

The problem that I have is that I need to order the children of each father, the result should be:

JavaScript

That is the only information I have, the father has type 1 and his children are next in the list types 0.

Any help please.

Thanks.

By the way, I have tried this but I’m stucked:

JavaScript

Advertisement

Answer

You could treat any same type as own group, sort them and take a flat array as result.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement