Mock
a = [{id:123},{id:1234},{id:12345}]
b = [{id:123},{id:1234},{id:123456}]
Code
a.filter((element)=> {
return b.some((ele) =>{
if (element.id === ele.id) {
return matched[element.id] = element.id
} else {
return unmatched[element.id] = element.id
}
});
});
Expected output
matched = {123: 123, 1234: 1234}
unmatched = {12345: 12345}
output
unmatched = {123: 123, 1234: 1234, 12345: 12345}
matched = {123: 123, 1234: 1234}
could any one help me out here. I am trying to compare two arrays and get the difference into different objects