The same user often arrives in pieces. A sign-up form gives a name and an email, a profile service adds an address, a billing export adds a phone number and another tag, and a CSV import repeats half of it with blanks. To show one row per person, the pieces have to be grouped by id and merged: later information wins, nested details are combined, lists are joined without repeats, and a blank never erases something already known.
Write mergeUsers(records) in merge-users.js. It returns one merged user per id, in the order each id first appears.
Records with the same id become one user; different ids stay separate. Users are listed in the order their id first appears.
Ids are compared exactly, as Map keys: 1 and "1" are different users. 0 and "" are valid ids.
A record that is not a plain object, or whose id is undefined or null, throws a TypeError.
Records are merged in order. For the same key, a later value replaces the earlier one.
When both values are plain objects, they are merged by these same rules, at every depth.
When both values are arrays, the later array's items are appended unless the merged array already includes them. Items are compared as includes compares them: NaN matches NaN, 1 does not match "1", and objects match only themselves: the same object used in two records gives one item (a copy), while two different objects with the same content give two.
A later null or undefined never replaces a value the merged user already has for that key. For a key the user does not have yet, it is stored.
0, "" and false are real values and replace earlier ones.
When the two values are of different kinds (an object and a string, an array and an object, null and an object), the later value replaces the earlier.
Dates and other objects that are not plain objects or arrays are taken as they are, never merged.
The records are not changed, and the users share no plain object or array with them.
A key named __proto__, at any depth, is ignored: it never changes a prototype or reaches Object.prototype.