here is logical question
this is my referenceArray
to compare and change with originalArray
const referenceArray = [
{ name: 'animal', source: ['duck', 'cat'], target: ['water', 'ground'] },
{ name: 'car', source: ['tata', 'kia'], target: ['tiago', 'sector'] },
{ name: 'bike', source: ['honda', 'hero'], target: ['livo', 'xtream'] },
{ name: 'vehicle', source: ['honda', 'hero'], target: ['hard', 'soft'] },
];
and this is i want to change the array originalArray
source and target values with the help of referenceArray
source and target
if its matched take name value and set thet value to originalArray
source and target
const originalArray = [
{ source: 'water', target: 'hero' },
{ source: 'tata', target: 'ground' },
{ source: 'livo', target: 'kia' },
{ source: 'hero', target: 'sector' },
];
here is the expected output how we want
const output1 = [
{ source: 'animal', target: ['bike', 'vehicle'] },
{ source: 'car', target: 'animal' },
{ source: 'bike', target: 'car' },
{ source: ['vehicle', 'bike'], target: 'car' },
];
const output2 = [
{ source: 'animal', target: 'bike' },
{ source: 'animal', target: 'vehicle' },
{ source: 'car', target: 'animal' },
{ source: 'bike', target: 'car' },
{ source: 'vehicle', target: 'car' },
{ source: 'bike', target: 'car' },
];
any output is acceptable for me if you get output2
that is more appreciable
I’m confusing how to achieve this data format without getting key value conflicts
please anyone can help me out please that is so appreciable
thanks advance