-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckLines.js
48 lines (36 loc) · 1.37 KB
/
checkLines.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Check for lines that are too long for Twitter, or that are duplicates too near to each other for Twitter, and log the results.
function checkLines (charLimit = 280, dupeLimit = 8) {
if (!Array.isArray(lines) || lines.length < 1) {
console.error('Invalid lines. Expected an array of strings. Received:', lines);
return;
}
if (lines.length < 2 * dupeLimit) {
console.error('List of lines is too short. Received length:', lines.length);
return;
}
console.log(`Checking ${work} for lines longer than ${charLimit} characters, and for duplicate lines within ${dupeLimit} indices of each other.`);
const longs = [];
const dupes = [];
let i, j, k;
for (i = 0; i < lines.length; i++) {
if (lines[i].length > charLimit) {
longs.push({ index: i, line: lines[i] });
}
for (j = 1; j <= dupeLimit; j++) {
k = i + j < lines.length ? i + j : -1 + j;
if (lines[i] === lines[k]) {
dupes.push({ index: i, line: lines[i] });
}
}
}
console.log('Longs:', longs);
console.log('Dupes:', dupes);
}
const worksObject = require('./works');
const works = Object.keys(worksObject);
const work = process.argv[2];
if (!works.includes(work)) {
throw new Error(`Invalid work: ${work}`);
}
const lines = require(`./lines/${work}`);
checkLines();