I have this data set
var records = [{
gc: '2',
time: 1231232423,
cards: [{
cardCode: '12121',
rssi: 23
}, {
cardCode: '12122',
rssi: 33
}, {
cardCode: '12421',
rssi: 43
}
]
},
{
gc: '3',
time: 4331232233,
cards: [{
cardCode: '6423',
rssi: 23
}, {
cardCode: '12421',
rssi: 13
}
]
}, , {
gc: '4',
time: 4331232233,
cards: [{
cardCode: '8524',
rssi: 03
},
{
cardCode: '6423',
rssi: 23
}, {
cardCode: '12421',
rssi: 67
}
]
}
]
I have an array(records) of objects and in each object there is an another array(cards). This means if i will always have cards array inside an object present in 'records'. So from very first i want to iterate over whole list records and compare the cards array of all objects with each other and then find the matched object's rssi value and push the object(that have minimum rssi value ) into another new array. In the same way at the end i want the array in which i have all the matching objects which have minimum rssi value. I am using lodash and have tried this
matchedRecords = records.forEach(record=>{
record.cards.forEach(record=>{
_.filter(records, _.flow(
_.property('cards'),
_.partialRight(_.some, { cardCode: record.cardCode })
));
})
})
My desired result would be
[
{
gc : 3,
cards : [{
cardCode : '12421',
rssi : 13
}]
}
]
Note : cards array object should be compare on the bassis of cardCode key
cardCode: '8524'should have an rssi of 30? If it's 3 it should be the minimum.recordsarray and find matching cards inside each cards array and find the object which has minimum rssi. In my above mentioned data set the object which havecardCodeequal to12421is present in all three objects ofrecordsso code should be return the object which has minimum rssi valuegc: 3come from in the result? The lowestrssifor one cardCode might be in a different record than the lowest rssi for another one.recordscardCode: '12421' is there. Basically i want to match records on the basis ofcardCodeand you can see that object with12421is present in all three objects insiderecordsand by comparing each object's rssi there is the minimum rssi of 13 withcardCode : 12421