Keeping track of the comics I've read can be a bit challenging, especially when some titles have issue numbers spread across multiple lines. Take for example the Avengers series that began in 2016 - here are the issue numbers listed in one cell:
#1-11
#1.1-5.1
#1MU
#672-676
To automatically calculate the total count of issues for each title, I attempted to write a script using regular expressions to extract and sum up the numbers. However, I'm encountering difficulties in correctly parsing the data and updating the counts as new issue numbers are added.
This is what I've come up with so far:
function calcIssueCount(x) {
// Initializing the count:
var issueCount = 0;
// Creating an array from the lines in the cell:
var box = x.split("\n");
for (var line in box) {
// Checking if there's a range of issue numbers:
if ("-" in line === True) {
// Removing unnecessary characters from the string:
line = line.replace("#","");
// Extracting the start and end numbers of the range:
var a = line.match(/[0-9}+\.|[0-9]+-/);
a = a.replace("-","");
var b = line.match(/-[0-9}+\.|[0-9]+/);
b = b.replace("-","");
// Converting extracted numbers into integers:
a = parseInt(a)
b = parseInt(b)
// Calculating the number of issues within the range:
var c = b - a + 1;
// Updating the total issue count:
issueCount += c;
}
else {
// If no range is found, consider it as a single issue:
issueCount += 1;
}
}
}
Function calcIssueCount(x)
should be called with the cell name (e.g., D15).
I suspect there might be mistakes in my approach, particularly in handling the cell data and converting it into an array. Can you point out where I may be going wrong?