This is regarding JavaScript. I have a response data like this which contains pairs of objects (note that the pairs can also be of 3 or 4 or any number and the pair ids are sorted). I want to alter the data such that after each matching pairs, I append one object.
[
  {
    pairId: 1,
    name: "abc",
    count: 10
  },
  {
    pairId: 1,
    name: "xyz
    count: 20
  },
  {
    pairId: 2,
    name: "abc"
    count: 15
  },
  {
    pairId: 2,
    name: "xyz,
    count: 25
  }
]
I want to achieve the data where I append one object after each matching pairs updating the count like this
[
  {
    pairId: 1,
    name: "abc",
    count: 10
  },
  {
    pairId: 1,
    name: "xyz
    count: 20
  },
  {
    pairId: 1,
    count: 30
  },
  {
    pairId: 2,
    name: "abc"
    count: 15
  },
  {
    pairId: 2,
    name: "xyz,
    count: 25
  }
  {
    pairId: 2,
    name: "mno,
    count: 5
  }
  {
    pairId: 2,
    count: 45
  }
]
Can anybody help achieve this?
While this question seems like a duplicate but I also wanted to know how to achieve pushing item to the end of last matching paired item.
 
     
     
    