topics/search/binary/rotatedList/index.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 7

Size

Lines of Code 32
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 17
mnd 6
bc 6
fnc 1
dl 0
loc 32
rs 10
bpm 6
cpm 7
noi 0
c 0
b 0
f 0
1
2
const find = (list, search, start = 0, end = -1) => {
3
    if (end === -1) {
4
        end = list.length - 1;
5
    } 
6
    // put your code here to address problems
7
    if (start === end) {
8
        if (list[start] === search) {
9
            return start;
10
        }
11
        //not found
12
        return -1;
13
    }
14
    let mid = parseInt((end + start) / 2);
15
16
    if (list[start] < list[end]) {
17
        // sorted sublist
18
        if (list[start] <= search && search <= list[mid]) {
19
            return find(list, search, start, mid);
20
        }
21
        return find(list, search, mid + 1, end);
22
    }
23
    // un-order sublist
24
    let check = find(list, search, start, mid);
25
    if (-1 === check) {
26
        check = find(list, search, mid + 1, end)
27
    }
28
    return check;
29
30
}
31
32
33
module.exports = find;
34