assume I have two list
const listA = [{"apple":100}, {"banana": 50}, {"pearl": 10}, {"cherry": 5}, {"kiwi": 3}]
const listB = [{"peach": 30}, {"apple": 15}, {"kiwi": 10}, {"mango": 5}]
The question is how do I merge two list into one stack up the same item with number increment and sort by the qty? I mean the final result should be ->
const listMerged = [{"apple":115}, {"banana": 50} , {"peach": 30}, {"kiwi": 13}, {"pearl": 10}, {"cherry": 5}, {"mango": 5}]
I know it is gonna be something like :
sortListDesc(list) {
return obj.sort(function (l1,l2) {
return l2< l1 ? -1
: l2 >l1 ? 1
: 0
})
}
but do not know exactly how to stack up the number, than sort by qty number.