There are three arrays containing data from the back-end, with unknown names or products. The task is to calculate the total amount spent by the user and how much money is left in their wallet. In case the user runs out of money, they can take a loan which will be added to their wallet.
I attempted to solve this using multiple loops to iterate through each array and compare values, but I require a solution with algorithmic complexity On.
var product = [
{'name':'cookie', 'price':10},
{'name':'coffee', 'price':2},
{'name':'ice cream', 'price':4},
{'name':'pasta', 'price':5},
{'name':'peach', 'price':6},
{'name':'pineapple', 'price':15},
]
var purse = [
{'name':'Katya', 'cash':100},
{'name':'Danya', 'cash':200},
{'name':'Vanya', 'cash':400},
{'name':'Sanya', 'cash':500},
{'name':'Manya', 'cash':600},
{'name':'Kira', 'cash':150},
]
var purchases = [
{'name':'Katya', 'item':'cookie'},
{'name':'Danya', 'item':'pasta'},
{'name':'Danya', 'item':'coffee'},
{'name':'Danya', 'item':'coffee'},
{'name':'Manya', 'item':'pineapple'},
{'name':'Katya', 'item':'ice cream','credit': 20},
]