const { rest, flow, map, toPairs, flatten, groupBy, head, last, fromPairs } = _
const fn = rest(flow(
objs => map(objs, toPairs), // map each object to pairs of [key, value]
flatten, // flatten to a single array of pairs
pairs => groupBy(pairs, head), // group the pairs by the key
groups => map(groups, group => map(group, last)), // create a new pair by taking the last element of each pair in the group
fromPairs // convert to an object
))
const A = { b: 'bar', c: 'baz', a: 'foo' }
const B = { a: 'aaa', b: 'bbb', c: 'ccc' }
const result = fn(A, B)
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>