Completed
Push — master ( b8c0d7...8cf4a8 )
by Pieter Epeüs
21s queued 10s
created

src/modules/multisort.js   A

Complexity

Total Complexity 7
Complexity/F 3.5

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
mnd 5
bc 5
fnc 2
dl 0
loc 30
rs 10
bpm 2.5
cpm 3.5
noi 0
c 0
b 0
f 0
1
module.exports = function multisort(original, key, direction) {
2
    let moveDirection = 1;
3
4
    if (direction === 'desc') {
5
        moveDirection = -1;
6
    }
7
8
    return original.sort((a, b) => {
9
        let nameA = a[key];
10
        let nameB = b[key];
11
12
        if (typeof nameA === 'string') {
13
            nameA = nameA.toUpperCase();
14
        }
15
16
        if (typeof nameB === 'string') {
17
            nameB = nameB.toUpperCase();
18
        }
19
20
        if (nameA < nameB) {
21
            return -1 * moveDirection;
22
        }
23
24
        if (nameA > nameB) {
25
            return 1 * moveDirection;
26
        }
27
28
        return 0;
29
    });
30
};
31