I've been banging my head on this the whole day, i give up:
I've created a function that receives (amongst others) a source-data-array and a target-data-array, both corresponding to respective sheet-ranges.
I want to extract addresses from the source-array, mold them a bit and unshift the result to the target array, after which the top element is popped. I first tried the recursive approach, but fell back to the while loop because of this. The problem is that with each loop, the addresses are shifted in some weird multiplied way. I dont know how to explain it but check out the log.
function arrZoekAdressen(strZoekGebied, arrBron, intRij, arrGebiedAdressen, arrActieveStraat) {
if (arrActieveStraat == undefined) {
arrActieveStraat = ["Geen adressen", "-"];
}
//#1
while (intRij < arrBron.length) {
if (arrBron[intRij][0] == strZoekGebied){
if (arrBron[intRij][2] == arrActieveStraat[0]){
arrActieveStraat[1] += ", " + arrBron[intRij][3] + arrBron[intRij][4];
} else {
Logger.log(arrGebiedAdressen);
Logger.log(arrActieveStraat);
arrGebiedAdressen.unshift(arrActieveStraat);
arrGebiedAdressen.pop();
Logger.log(arrGebiedAdressen);
arrActieveStraat[0] = arrBron[intRij][2];
arrActieveStraat[1] = arrBron[intRij][3] + arrBron[intRij][4];
}
}
intRij++;
}
//#2
arrGebiedAdressen.unshift(arrActieveStraat);
arrGebiedAdressen.pop();
return arrGebiedAdressen;
};
The produced log with these loggers looks as follows, check out the array contents, utterly weird!
FIRST LOOP [17-02-07 07:54:11:181 PST] [[, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
[17-02-07 07:54:11:181 PST] [Geen adressen, -]
[17-02-07 07:54:11:182 PST] [[Geen adressen, -], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
SECOND LOOP [17-02-07 07:54:11:183 PST] [[Cuyleborg, 212, 226], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
[17-02-07 07:54:11:183 PST] [Cuyleborg, 212, 226]
[17-02-07 07:54:11:184 PST] [[Cuyleborg, 212, 226], [Cuyleborg, 212, 226], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
THIRD LOOP [17-02-07 07:54:11:185 PST] [[Moselborg, 10, 88], [Moselborg, 10, 88], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
[17-02-07 07:54:11:185 PST] [Moselborg, 10, 88]
[17-02-07 07:54:11:186 PST] [[Moselborg, 10, 88], [Moselborg, 10, 88], [Moselborg, 10, 88], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
etc. etc.
The source list looks like this:
NR CITY Cuyleborg 212
NR CITY Cuyleborg 226
NR CITY Moselborg 10
NR CITY Moselborg 88
Of course every street should occur only once in the array since you would expect the other streets with every unshift to move up one index.
Please help...