I am trying to find the difference between the elements in the complex array.
I have array list as follows:
[
[{
id: 123,
list: [{
name: "Vimal",
status: "Pass"
}, {
name: "Selvam",
status: "Pass"
}]
}],
[{
id: 124,
list: [{
name: "Vimal",
status: "Pass"
}, {
name: "Selvam",
status: "Fail"
}, {
name: "Raj",
status: "Pass"
}]
}]
]
I would like to get the difference between the list
as follows:
[{
id: 123,
list: [{
name: "Selvam",
status: "Pass"
}]
}, {
id: 124,
list: [{
name: "Selvam",
status: "Fail"
}, {
name: "Raj",
status: "Pass"
}]
}]
I was thinking to loop each element and compare with the adjacent element, then store the differences into the temporary variable. But that sounds too cumbersome approach. I just wanted your opinion on how do I change my way of looking this problem. Pointers would be more helpful. Otherwise, is there any library which could solve this problem easily?
Edit1: Please note that the list will always not a length of 2. The size is dynamic. And the comparison should happen between all elements.