Lines of Code | 39 |
Duplicated Lines | 39 |
Ratio | 100 % |
Coverage | 56.25% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | /** |
||
5 | View Code Duplication | "use strict"; |
|
|
|||
6 | |||
7 | /** |
||
8 | * Class with Queen logic |
||
9 | */ |
||
10 | class Queen { |
||
11 | /** |
||
12 | * init |
||
13 | */ |
||
14 | constructor(color) { |
||
15 | 4 | this.symbol = "Q"; |
|
16 | 4 | this.moved = 0; |
|
17 | 4 | this.active = true; |
|
18 | 4 | this.color = color; |
|
19 | 4 | this.rows = [null, "A", "B", "C", "D", "E", "F", "G", "H"]; |
|
20 | 4 | this.img = this.color === "white" ? "w-queen" : "b-queen"; |
|
21 | } |
||
22 | |||
23 | legalMove(x, y, nx, ny) { |
||
24 | // row |
||
25 | 6 | if (x == nx && y !== ny || x !== nx && y == ny) { |
|
26 | return true |
||
27 | } |
||
28 | |||
29 | let xNum = this.rows.indexOf(x); |
||
30 | let nxNum = this.rows.indexOf(nx); |
||
31 | |||
32 | let xStep = Math.abs(xNum - nxNum); |
||
33 | let yStep = Math.abs(y - ny) |
||
34 | 2 | if (xStep === yStep) { |
|
35 | return true |
||
36 | } |
||
37 | |||
38 | return false; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | |||
43 | module.exports = Queen; |
||
44 |