These are the responses retrieved from the API:
const attractions = [
{"id": 1,"name": "drive on avenue"},
{"id": 2, "name": "diving"},
{"id": 3,"name": "visiting mangroove"},
];
const reviews = [
{"id": 1,"score": 1.5},
{"id": 2, "score": 2} ,
{"id": 3,"score": 5.5},
{"id": 3,"score": 4},
{"id": 2,"score": 3},
{"id": 1,"score": 3.5},
{"id": 3,"score": 5},
{"id": 2,"score": 4}
]
The anticipated result should be as follows:
[{"name": "drive on avenue", "score": 2.5},
{"name": "diving", "score": 3},
{"name": "visiting mangroove", "score": 4.83}
]
I attempted to utilize reduce
, however, it summed up all scores together. How can I compute the average score for each ID?