Seeking a solution in Angular 7 for a problem involving the creation of a function that operates on two arrays of objects. The goal is to generate a third array based on the first and second arrays.
The structure of the third array closely resembles the first array, with the key count
within the children
array being influenced by the presence or absence of corresponding children
in the second array. Is there an angular array mapping function capable of handling this task?
First Array:
[
{
"name": "Category 1",
"value": "Vegetables",
"children": [
{"name": "Carrots", "value": "Carrots", "count": 2},
{"name": "Peas", "value": "Peas", "count": 1}
]
},
{
"name": "Category 2",
"value": "Fruits",
"children": [
{"name": "Apples", "value": "Apples", "count": 10},
{"name": "Bananas", "value": "Bananas", "count": 5}
]
},
{
"name": "Category 3",
"value": "Desserts",
"children": [
{"name": "Ice Cream", "value": "IceCream", "count": 3},
{"name": "Cakes", "value": "Cakes", "count": 3}
]
}
]
Second Array
[
{
"name": "Category 1",
"value": "Vegetables",
"children": [
{"name": "Peas", "value": "Peas", "count": 1}
]
},
{
"name": "Category 2",
"value": "Fruits",
"children": [
{"name": "Apples", "value": "Apples", "count": 3},
{"name": "Bananas", "value": "Bananas", "count": 2}
]
},
{
"name": "Category 3",
"value": "Desserts",
"children": []
}
]
Third Array
[
{
"name": "Category 1",
"value": "Vegetables",
"children": [
{"name": "Carrots", "value": "Carrots", "count": 0},
{"name": "Peas", "value": "Peas", "count": 1}
]
},
{
"name": "Category 2",
"value": "Fruits",
"children": [
{"name": "Apples", "value": "Apples", "count": 3},
{"name": "Bananas", "value": "Bananas", "count": 2}
]
},
{
"name": "Category 3",
"value": "Desserts",
"children": [
{"name": "Ice Cream", "value": "IceCream", "count": 0},
{"name": "Cakes", "value": "Cakes", "count": 0}
]
}
]