I am using Angular as my framework. I have a function that is called whenever the array has been mutated. I need to check the array every time this function is called to see if it has duplicate items and if it does I need to edit the original item and remove the last item from the array.
I am building a shopping cart. so when a duplicate item is added to the array I need to change the quantity value in the original item and remove the last pushed item.
component function:
ngDoCheck() {
    var changes = this.differ.diff(this.shoppingCart); // check for changes
    if (changes) {
      clearTimeout(this.timer);
      this.cartOpen = true;
      this.itemsInCart = this.numberOfItemsinCart(this.shoppingCart);
      this.cartTotal = this.totalCartAmount(this.shoppingCart);
     //check if this.shoppingCart has a duplicate item
     //if array does have a duplicate 
     //change qty value in original item and
     //remove the last item added
   }
 }
My array of objects example:
{
    "id": 6,
    "product_name": "name of product",
    "sku": "26-008b",
    "description": "description of product",
    "product_link": "link",
    "cat_id": "categoryId",
    "cat_name": "Category name",
    "related_products": [],
    "sub_cat_name": "sub category name",
    "price": price,
    "qty": 1
}
ANy help would be greatly appreciated as I am out of ideas or have been staring at this code for too long.
 
     
    