There is a single array that holds appointmentID
(first value) and supperBillID
(second value) separated by a comma. The AppointmentID
will always be unique, but the superBillID
can be repeated in consecutive positions. The goal is to create an array that groups all appointmentID
values with the same billingID
, separated by commas.
I have attempted to write the following code, but it is not producing the desired output:
var fg = ['10000021,23', '10000022,23', '10000023,24', '10000024,25', '10000025,25', '10000026,25', '10000027,26', '10000028,27'];
var tab = [];
var gbl = 0;
for (var i = 0; i < fg.length; i++, gbl++) {
var vb = fg[gbl].split(',')[1]; // Will use try catch here
var mainAr = fg[gbl].split(',')[0];
for (var j = i + 1; j < fg.length; j++) {
if (vb == fg[j].split(',')[1]) {
mainAr = mainAr + ',' + fg[j].split(',')[0];
gbl++;
}
else {
break;
}
tab.push(mainAr, vb);
}
}
Sample Input:
var input = ['10000021,23', '10000022,23', '10000023,24', '10000024,25', '10000025,25', '10000026,25', '10000027,26', '10000028,27'];
Expected Output:
output = ['10000021,10000023',23]
['10000023',24]
['10000024,10000025,10000026',25]
['10000027',26]
['10000028',27]