Consider the following scenario where I have 2 arrays:
categories = ["hotels", "transfers","food","transfers"]
amounts = [1500, 250, 165, 150]
The goal is to create an object that will look like this:
result = {hotels: 1500, transfers: 400, food: 165}
To achieve this, a function needs to be implemented that iterates over the categories array and populates the result object. The keys of the object should be unique elements from the categories array, while the values should be the corresponding amounts. If there are repeated elements in the categories array, the function should sum up their amounts.
I have attempted various approaches such as using nested forEach loops and for loops without success. Any help or guidance would be greatly appreciated!