Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 21 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | export const getTreePathFromId = (flatData, id) => { |
||
2 | const res = []; |
||
3 | const node = flatData.find(n => n.get('_id') === id); |
||
4 | const finder = n => n.get('_id') === lastParentId; |
||
|
|||
5 | let lastParentId = node.get('_id'); |
||
6 | |||
7 | while (lastParentId !== undefined) { |
||
8 | const parent = flatData.find(finder); |
||
9 | |||
10 | if (parent) { |
||
11 | res.push(parent.get('_id')); |
||
12 | lastParentId = parent.get('_parentId'); |
||
13 | } |
||
14 | |||
15 | else { |
||
16 | lastParentId = undefined; |
||
17 | } |
||
18 | } |
||
19 | |||
20 | return res.reverse(); |
||
21 | }; |
||
22 |