GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

src/util/findTreeNode.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 5

Size

Lines of Code 51
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 10
nc 1
mnd 3
bc 7
fnc 2
dl 0
loc 51
rs 10
bpm 3.5
cpm 5
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C findTreeNode.js ➔ ??? 0 49 9
1
import { List, Map, fromJS } from 'immutable';
2
3
export const findTreeNode = (
4
    treeData,
5
    path,
6
    childIdentifier = 'children',
7
    rootIdentifier = 'root'
8
) => {
9
10
    if (!Map.isMap(treeData)) {
11
        treeData = fromJS(treeData);
12
    }
13
14
    if (!List.isList(path)) {
15
        path = fromJS(path);
16
    }
17
18
    const lookingFor = path.last();
19
20
    let node = treeData.get(rootIdentifier);
21
    const indexPath = [rootIdentifier];
22
23
    const firstId = path.first();
24
    path = path.shift();
25
26
    if (node.get('id') === firstId) {
27
28
        while (path.count() > 0 && node) {
29
30
            if (node
31
                && node.get('id') !== lookingFor
32
                && node.get(childIdentifier)) {
33
34
                const nextId = path.first();
35
                path = path.shift();
36
37
                const nodeIndex = node.get(childIdentifier)
38
                    .findIndex(n => n.get('id') === nextId);
39
                node = node.getIn([childIdentifier, nodeIndex]);
40
                indexPath.push(childIdentifier);
41
                indexPath.push(nodeIndex);
42
            }
43
44
            else {
45
                node = null;
46
            }
47
        }
48
    }
49
50
    return { node, indexPath };
51
};
52