0
I have a very complex logic problem. I have to compare 4 arrays and make them work together. I will explain it better
Example of how it can come:
var mesA = [ "fev", "mar", "jun" ]
var valorA = [ 50, 50, 50 ]
var mesB = [ "jan", "fev", "mar", "jul", "ago" ]
var valorB = [ 25, 25, 25, 25, 25 ]
var mesA_Final = []
var valorA_Final = []
var mesB_Final = []
var valorB_Final = []
How should the output of this:
var mesA_Final = [ "jan", "fev", "mar", "jun", "jul", "ago" ]
var valorA_Final = [ 0, 50, 50, 50, 0, 0 ]
var mesB_Final = [ "jan", "fev", "mar", "jun", "jul", "ago" ]
var valorB_Final = [ 25, 25, 25, 0 25 25 ]
I need to compare these 2 arrays, sort them by month name, and compare both arrays so that they draw their differences and enter value 0
in the month one has and the other has not, and vice versa.
Obs¹: these 4 arrays will always come with correct month and value, if for example come 3 months, will come 3 values.
Obs²: What will come in double arrays is dynamic, can come 1 month 1 value, as can come 2 months 2 values, 3 months 3 values (...)
The most I got was this: Jsfiddle
Does anyone have any idea?
You have values that are linked and different arrays, why not make an array of objects that have
mes
andvalor
? It would be much easier to sort. For example:mesA = [{mes: 'jan', valor: 50}, {mes: 'fev', valor: 50}, {mes: 'mar', valor: 50}];
– Lucas Henrique
'Cause the way it is now, to order the way you want it to be too hard and hard to understand.
– Lucas Henrique
I think I made some progress with your code, check it out: https://jsfiddle.net/ukz5uves/1/
– Renato Diniz