-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataTypes9.txt
174 lines (146 loc) · 4.75 KB
/
dataTypes9.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
1.
if (diff.hours + diff.days * 24 >= Math.floor((duration * 1000) / (1000 * 60 * 60))) {
return false;
} else {
return true;
}
=>
const activeHours = Math.floor((duration * 1000) / (1000 * 60 * 60));
const totalHours = diff.hours + diff.days * HOURS_PER_DAY;
if (totalHours >= activeHours) {
return false;
} else {
return true;
}
//упрощение условия, создание константы вместо магического значения
2.
this.setActivePotionHeader({
id: potionId,
duration: this.activePotions[potionId - 1].duration,
start: String(new Date()),
});
=>
this.setActivePotionHeader({
id: potionId,
duration: this.activePotions[potionId - 1].duration,
start: new Date(),
});
//устранение приведения типов
3.
let characterElement: ICharacterElement = {
id: element.id,
layer: element.layer,
idInLayer: Number(element.idInLayer),
generationId: Number(element.generationId),
link: element.link,
price: Number(element.price),
count: Number(element.count),
limit: Number(element.limit),
sale: Number(element.sale),
effect: JSON.parse(element.effect),
};
=>
let characterElement: ICharacterElement = {
id: element.id,
layer: element.layer,
idInLayer: Number(element.idInLayer),
generationId: Number(element.generationId),
link: element.link,
price: element.price,
count: element.count,
limit: element.limit,
sale: element.sale,
effect: JSON.parse(element.effect),
};
//устранение приведения типов
4.
sale > 0 && limit > 0 &&
(myPotions && myPotions[potionId - 1].count === 0) &&
Math.floor((sale * 100) / (price + sale)) > 0
=>
const isPromoNotEmpty = sale > 0 && limit > 0;
const isMyPotionsNotEmpty = myPotions && myPotions[potionId - 1].count > 0;
const isSaleNotEmpty = Math.floor((sale * 100) / (price + sale)) > 0;
isPromoNotEmpty && isMyPotionsNotEmpty === false && isSaleNotEmpty
//упрощение условия
5.
(Number(expiredTime.split("h")[0]) * 60 +
Number(expiredTime.split("h")[1].split("m")[0])) /
(storePotions.activePotions[potionId - 1].duration * 60)
=>
const getExpiredDate = (expiredTime: string) => {
let expiredHours = Number(expiredTime.split("h")[0]) * 60
let expiredMinutes = Number(expiredTime.split("h")[1].split("m")[0])
if (storePotions.activePotions[potionId - 1].duration === 0) {
return;
}
return (expiredHours + expiredMinutes) / (storePotions.activePotions[potionId - 1].duration * 60)
}
//добавлена проверка деления на ноль
6.
storeUser.stateVibration === "true"
=>
Boolean(storeUser.stateVibration) === true
//добавлено приведение типов
7.
this.energy.countEnergy = Math.floor(this.energy.elapsedTime / intervalOfUpdateEnergy)
=>
const getCountEnergy = (intervalOfUpdateEnergy: number) => {
if (intervalOfUpdateEnergy === 0) {
return;
}
return Math.floor(this.energy.elapsedTime / intervalOfUpdateEnergy);
}
//добавление проверки деления на ноль
8.
if (error === "Username does not exist") {}
=>
const ERROR_EXISTING_USERNAME = "Username does not exist";
if (error === ERROR_EXISTING_USERNAME) {}
//добавление константы
9.
def GOST():
...
percent = 100 / len(blocksBin)
...
=>
def GOST():
...
percent = 100 / len(blocksBin)
if percent === 0:
return None
...
//добавление проверки деления на ноль
10.
x2 = 0
for i in range(len(dict)):
if bukvaArray[i].chastota != 0:
x2+=pow((bukvaArray[i].chastota / len(shifrotext) - freq[i]), 2) / (freq[i])
return x2
=>
x2 = 0
for i in range(len(dict)):
if wordsList[i].frequency == 0 or len(encodedText) == 0 or frequency[i] == 0:
return None
x2+=pow((wordsList[i].frequency / len(encodedText) - frequency[i]), 2) / (frequency[i])
return x2
//добавление проверки деления на ноль
11.
const elementFormat = String(element).length > 1 ? String(element) : "0" + String(element);
=>
const hoursFormat = (element: string) => {
return element.length > 1 ? element : "0" + element;
};
//избавление от приведения типов
12. if (warriorCharacteristics[0].action === duelAction.giveUp ||
warriorCharacteristics[1].action === duelAction.giveUp ||
(warriorCharacteristics[1].health <= 0 &&
warriorCharacteristics[1].action !== duelAction.protection &&
current !== 1))
=>
const isLost = warriorCharacteristics[1].health <= 0 &&
warriorCharacteristics[1].action !== duelAction.protection &&
current !== 1
if (warriorCharacteristics[0].action === duelAction.giveUp ||
warriorCharacteristics[1].action === duelAction.giveUp || isLost)
//упрощение условия