Total Complexity | 13 |
Complexity/F | 6.5 |
Lines of Code | 42 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /*jslint |
||
5 | function id2alpha(id) { |
||
6 | 'use strict'; |
||
7 | |||
8 | if (id >= 0 && id < 26) { |
||
9 | return String.fromCharCode('A'.charCodeAt() + (id % 26)); |
||
10 | } |
||
11 | if (id >= 26 && id < 260) { |
||
12 | return String.fromCharCode('A'.charCodeAt() + (id % 26)) + |
||
13 | String.fromCharCode('0'.charCodeAt() + (id / 26)); |
||
14 | } |
||
15 | |||
16 | return ""; |
||
17 | } |
||
18 | |||
19 | |||
20 | function alpha2id(alpha) { |
||
21 | 'use strict'; |
||
22 | |||
23 | if (alpha.length < 1 || alpha.length > 2) { |
||
24 | return -1; |
||
25 | } |
||
26 | |||
27 | alpha = alpha.toLowerCase(); |
||
28 | var letter = 0, |
||
29 | number = 0; |
||
30 | |||
31 | if (alpha[0] >= 'a' && alpha[0] <= 'z') { |
||
32 | letter = alpha.charCodeAt(0) - 'a'.charCodeAt(0); |
||
33 | } else { |
||
34 | return -1; |
||
35 | } |
||
36 | |||
37 | if (alpha.length === 2) { |
||
38 | if (alpha[1] >= '0' && alpha[1] <= '9') { |
||
39 | number = alpha.charCodeAt(1) - '0'.charCodeAt(0); |
||
40 | } else { |
||
41 | return -1; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | return number * 26 + letter; |
||
46 | } |
||
47 |