-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-rules.js
31 lines (26 loc) · 997 Bytes
/
python-rules.js
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
function pythonContent(content) {
// ######### PYTHON RULES IDEAS #########
// Store the original content length
var originalLength = content.length;
// Example 1: Remove the requirement for variable and print it directly - RULE 0
var linez = content.split('\n');
for (var i = 0; i < linez.length; i++) {
var line = linez[i];
var match = line.match(/^(\w+) = "(.+)"$/);
if (match) {
var variable = match[1];
var value = match[2];
for (var j = i + 1; j < linez.length; j++) {
linez[j] = linez[j].replace(new RegExp('\\b' + variable + '\\b', 'g'), '"' + value + '"');
}
linez.splice(i, 1);
i--;
}
}
content = linez.join('\n');
// Calculate the difference in character count
var difference = originalLength - content.length;
var calculate = (difference / originalLength) * 100;
var percentage = calculate.toFixed(2);
return {content: content, original: originalLength, difference: difference, percentage: percentage};
}