src/Resources/public/js/table_init.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 2.67

Size

Lines of Code 28
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 19
c 0
b 0
f 0
dl 0
loc 28
rs 10
mnd 5
bc 5
fnc 3
bpm 1.6666
cpm 2.6666
noi 1
1
(function ($) {
2
    $(document).ready(function () {
3
        $('table').tablesort({
4
            compare: function(a, b) {
5
                // Manage int, cast into int to have good result
6
                if (!isNaN(a) && !isNaN(b)) {
7
                    a = Number.parseInt(a);
8
                    b = Number.parseInt(b);
9
                } else {
10
                    // Manage prices, keep only number and cast int to int
11
                    if (a.match(moneyRegex)) {
0 ignored issues
show
Bug introduced by
The variable moneyRegex seems to be never declared. If this is a global, consider adding a /** global: moneyRegex */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
12
                        a = Number.parseInt(a.replace(/\D/g,''));
13
                    }
14
                    if (b.match(moneyRegex)) {
15
                        b = Number.parseInt(b.replace(/\D/g,''));
16
                    }
17
                }
18
                if (a > b) {
19
                    return 1;
20
                } else if (a < b) {
21
                    return -1;
22
                } else {
23
                    return 0;
24
                }
25
            }
26
        });
27
    });
28
})(window.Zepto || window.jQuery);
29