I have retrieved a list of menus from the database, labeled "sample," shown below:
[
{ id: 1, name: 'Main Menu', branch: 1, subbranch1: 0, subbranch2: 0 },
{ id: 2, name: 'Main Menu 2', branch: 2, subbranch1: 0, subbranch2: 0 },
{ id: 3, name: 'Sub Menu 1-1', branch: 1, subbranch1: 1, subbranch2: 0 },
{ id: 4, name: 'Sub Menu 1-2', branch: 1, subbranch1: 2, subbranch2: 0 },
{ id: 5, name: 'Sub Menu 1-2-1', branch: 1, subbranch1: 2, subbranch2: 1 },
{ id: 6, name: 'Sub Menu 2-1', branch: 2, subbranch1: 1, subbranch2: 0 },
{ id: 7, name: 'Sub Menu 2-2', branch: 2, subbranch1: 2, subbranch2: 0 },
]
Each menu in this list is assigned values for branch, subbranch1, and subbranch2 which determine its position in the menu hierarchy. A menu can act as a clickable item or serve as a group heading for other menus (essentially acting as a parent).
For instance, Menu with id 1 has submenus 3 and 4 under it as subbranch1, and Menu with id 4 has submenu 5 under it as subbranch2.
I am seeking to identify all the menus that do not have any children (in other words, they are clickable menus rather than group menus).
The final result for the "given sample" should be:
[
{ id: 3, name: 'Sub Menu 1-1', branch: 1, subbranch1: 1, subbranch2: 0 },
{ id: 5, name: 'Sub Menu 1-2-1', branch: 1, subbranch1: 2, subbranch2: 1 },
{ id: 6, name: 'Sub Menu 2-1', branch: 2, subbranch1: 1, subbranch2: 0 },
{ id: 7, name: 'Sub Menu 2-2', branch: 2, subbranch1: 2, subbranch2: 0 },
]