You're given an array of row objects, each tagged with a user field plus one or more other fields. Different rows can describe the same user — one row carries their name, another their age. Your job is to consolidate every row belonging to a user into a single record, so each user appears exactly once in the output. This is a shallow merge per group, the same idea as Object.assign applied to each user's rows in turn.
// rows: Array<{ user: string } & Record<string, unknown>>
// each row has a `user` field plus any number of other fields.
// returns: Array<{ user: string } & Record<string, unknown>>
// one merged record per user, in the order each user was FIRST seen.
function dataMerging(rows): Array<object>;
// Two rows for 'ada' carry disjoint fields; they merge into one record.
dataMerging([
{ user: 'ada', name: 'Ada' },
{ user: 'ada', age: 36 },
{ user: 'linus', name: 'Linus' },
]);
// → [{ user: 'ada', name: 'Ada', age: 36 }, { user: 'linus', name: 'Linus' }]
// When two rows set the same field, the LATER row wins.
dataMerging([
{ user: 'ada', role: 'guest' },
{ user: 'ada', role: 'admin' },
]);
// → [{ user: 'ada', role: 'admin' }]
user, return an array. Rows with the same user collapse into one record; the output is an array of those records, not an object.role, the value from the row that appears later in the input wins.user field. It stays on every merged record.dataMerging([]) returns [].