I have got an array that contains data in hierarchical form such as:
Level 2
chapter 1
chapter 2
Level 4
chapter 1
chapter 2
Level 1
chapter 1
chapter 2
Level 3
chapter 1
chapter 2
If I just call array.sort(), the hierarchy gets disturbed. So, I have to develop my own way of sorting items. The thing I can't understand is, how would I compare two levels such that I would know that level 1 is less than level 2 and it should be at the top index of the array?
Arrayor just anObject['level2', 'chapter1', 'chater2', 'level4']etc