javascript - Ask a question about js to json traversal
淡淡烟草味2017-05-19 10:35:55
0
4
451
For example, if I want to find an id of 4, I should return [1,3,4] If I want to find an id of 9, I should return [1,3 ,9] The id you want to find is 7, change it to return [6,7]
I don’t know if I made it clear. Thanks for the answer
Many people are complaining that you didn’t post the code, but those who can answer the questions are sincere! Simplified version of the original experimental data (also for others to verify their own solutions)
Direct recursive traversal, first check whether the ids are the same, return directly if they are the same, if they are different, check whether there are children. If there are children, record the id of the current layer and continue to traverse downwards. If not, clear the record and skip the current node and traverse The next node at the same level.
Many people are complaining that you didn’t post the code, but those who can answer the questions are sincere!
Simplified version of the original experimental data (also for others to verify their own solutions)
JS search output results
Can you post the code... It's hard to process a picture like this...
Direct recursive traversal, first check whether the ids are the same, return directly if they are the same, if they are different, check whether there are children. If there are children, record the id of the current layer and continue to traverse downwards. If not, clear the record and skip the current node and traverse The next node at the same level.