I have an array with the following elements:
https://i.sstatic.net/6YzUp.png
Once I encounter 'finished', I split it and aim to showcase, for each string containing 'Getting', its corresponding links with 'HTTP_404'
This is my current code :
var input = ['urlGettingF', '├─BROKEN─aquaHTTP_404', '├─BROKEN─url1HTTP_404', 'ok', 'urlok', 'Finished',
'urlGettingF2', '├─BROKEN─url1HTTP_404', '├─BROKEN─url21HTTP_404', 'Finished',
'urlGettingF3', 'url3ok', 'ok', 'Finished',
'urlGettingF4', 'url4ok', 'ok', 'Finished'
];
var inputDecouped = [];
let Test=[];
let start = '';
let pageGetting='';
let liens =[];
let pages=[];
let ok= false;
let reference = {};
let grouped = {};
// Function to split the input into multiple arrays based on 'Finished'
function ArrayToMultipleArrays(array) {
let result = [[]];
let index = 0;
array.forEach((x, i) => {
//console.log(index, i, x)
// We will create arrays based on the value of x
result[index].push(x);
if ((i + 1) < array.length && x.includes('Finished')) {
index++;
result[index] = [];
}
});
return result
}
inputDecouped = ArrayToMultipleArrays(input);
for(let i=0; i<inputDecouped.length; i++){
for(let k = 0 ; k< inputDecouped[i].length; k++ ){
if(inputDecouped[i][k].indexOf('Getting') > -1 || inputDecouped[i][k].indexOf('HTTP_404') > -1 ){
if(inputDecouped[i][k].indexOf('Getting') > -1 ){
start = inputDecouped[i][k];
pageGetting = start;
ok= true
//pages.push(({id:i, page: inputDecouped[i][k]}));
}
else if(inputDecouped[i][k].indexOf('HTTP_404') > -1 ){
if(ok === true){
liens=[];
ok = false;
}
liens.push(inputDecouped[i][k]);
}
}
}
Test.push(({page:pageGetting, lien: liens}));
}
console.log(Test);
Upon execution, the output shown is:
https://i.sstatic.net/l0133.png
However, I desire the resulting output to be as follows:
[[object Object] {
lien: ["├─BROKEN─aquaHTTP_404", "├─BROKEN─url1HTTP_404"],
page: "urlGettingF"
}, [object Object] {
lien: ["├─BROKEN─url1HTTP_404", "├─BROKEN─url21HTTP_404"],
page: "urlGettingF2"
}]
My jsbin snippet can be found here : https://jsbin.com/loqagekiji/edit?js,console
What changes should be made to rectify this issue?