My goal is to convert a version string to a number using the following code:
function convertVersionToNumber(line) {
const groups = line.matchAll(/^# ([0-9]).([0-9][0-9]).([0-9][0-9])\s*/g);
return parseInt(groups[1] + groups[2] + groups[3]);
}
convertVersionToNumber("# 1.03.00")
I encountered an issue where groups
is an
IterableIterator<RegExpMatchArray>
and not an array. I tried using Array.from
, but it didn't work as expected. Is there a simple way to convert groups
into an array, ideally in a concise manner?
The API for
IterableIterator<RegExpMatchArray>
seems inconvenient, especially when trying to skip the first element in a for...of
loop. I am looking for a more concise solution to handle this without adding excessive lines of code. I am working with TypeScript, so any syntactic sugar that can simplify this task would be greatly appreciated.