I´m having problems building and algorithm to do the following:
I want to loop over an array that contains all versions tags from a Gitlab project, like this:
versions = [
{
"name": "2.0.1"
},
{
"name": "2.0.0"
},
{
"name": "1.0.14"
},
{
"name": "1.0.13"
},
{
"name": "1.0.12"
},
...
]
And I want to compare these tags through a gitlap endpoint and save the information retreived.
The comparison needs to be done by two tags, so for cover all the tags will need to be done as follows:
Compare the first value of the array "2.0.1" with the second one "2.0.0"
and Save the data retreived into the first array element "2.0.1".
Compare the second value of the array "2.0.0" with the third one "1.0.14"
and Save the data retreived into the second array element "2.0.0".
Compare the third value of the array "1.0.14" with the fourth one "1.0.13"
and Save the data retreived into the third array element "1.0.14".
Compare the fourth value of the array "1.0.13" with the fifth one "1.0.12"
and Save the data retreived into the third fourth array element "1.0.13".
etc.
So I understand that it will be something similar to this:
var versions = [ {"name": "2.0.1"}, {"name": "2.0.0"}, {"name": "1.0.14"}, {"name": "1.0.13"}, {"name": "1.0.12"}, ... ];
for( var version in versions){
var new_tag = ...
var old_tag = ...
var diference = compare(old_tag, new_tag);
//and save the difference into the versions old_tag index
}
This is the result I expect to have:
var versions = [
{
"name": "2.0.1",
"difference": "difference retreived comparing 2.0.1 and 2.0.0"
},
{
"name": "2.0.0",
"difference": "difference retreived comparing 2.0.0 and 1.0.14"
},
{
"name": "1.0.14",
"difference": "difference retreived comparing 1.0.14 and 1.0.13"
},
{
"name": "1.0.13",
"difference": "difference retreived comparing 1.0.13 and 1.0.12"
},
{
"name": "1.0.12",
"difference": "difference retreived comparing 1.0.12 and ..."
},
...
]
Is not a must to save it in the versions array, it can be saved in a new created array but the information has to be like that.
Can someone help to finisht this algorithm?
Thanks in advance.
I did some mucking about here, and came up with the following code.
<cfscript>
versions = [
{
"name": "2.0.1"
},
{
"name": "2.0.0"
},
{
"name": "2.0.0"
},
{
"name": "1.0.14"
},
{
"name": "1.0.13"
},
{
"name": "1.0.12"
}
];
for (version in versions) {
position = arrayfind(versions, version);
if (position < arraylen(versions)) {
if (versions[position].name is not versions[position + 1].name) {
writedump(position & " " & versions[position].name & " is not " & versions[position + 1].name);
}
else {
writedump(position & " " & versions[position].name & " is the same as " & versions[position + 1].name);
}
}
}
</cfscript>
You will want to use the StructInsert
function to modify your data. I'll leave that in your capable hands.