I have a array of version numbers looking like this:
[
{
"name": "v12.3.0.pre",
},
{
"name": "v12.2.5",
},
{
"name": "v12.2.4",
},
{
"name": "v12.2.3",
},
{
"name": "v12.2.1",
},
{
"name": "v12.2.0",
},
{
"name": "v12.2.0.pre",
},
{
"name": "v12.2.0-rc32",
},
{
"name": "v12.2.0-rc31",
},
{
"name": "v12.1.9",
},
{
"name": "v12.1.8",
},
{
"name": "v12.1.6",
},
{
"name": "v12.1.4",
},
{
"name": "v12.1.3",
},
{
"name": "v12.1.2",
},
{
"name": "v12.1.1",
},
{
"name": "v12.1.0",
},
{
"name": "v12.1.0.pre",
},
{
"name": "v12.1.0-rc23",
},
{
"name": "v12.1.0-rc22",
},
{
"name": "v12.0.9",
},
{
"name": "v12.0.8",
},
{
"name": "v12.0.6",
},
{
"name": "v12.0.4",
},
{
"name": "v12.0.3",
},
{
"name": "v12.0.2",
},
{
"name": "v12.0.1",
},
{
"name": "v12.0.0",
},
{
"name": "v11.12.0.pre",
},
{
"name": "v11.11.8",
}
]
From this array I would like to determine the latest version, which do not end with '.pre' or include 'rc.
I'm iterating through the array with a for-loop, and filtering out the '.pre' and 'rc' with an if statement. I then use split/join to remove the first 'v' character. So far so good. Then I'm left with values like '12.2.5' and '11.12.10'. I first thought of removing the dots, then use a 'greater than' operator to see find the highest value, but then '11.12.10(111210)' would result greater than '12.2.5(1225)' which would not work out in my case.
for(i in arr){
if(!arr[i].name.endsWith('.pre') && !arr[i].name.includes('rc')){
var number = number.split('v').join("");
var number = number.split('.').join("");
}
}
Any ideas on best way to solve this? Thanks!