A form library reads a form's fields as a list of [name, value] pairs and needs them as an object to send. A URL's query string arrives as pairs too. Going the other way, a settings object has to become a list of rows to show in a table, or to sort and filter with array methods before it turns back into an object. Pairs and objects are two shapes of the same data, and moving between them has a few sharp edges.
Write fromPairs(pairs) and toPairs(object) in pairs.js, without Object.fromEntries or Object.entries.
It returns a new plain object (one that inherits from Object.prototype) with a property for each pair.
When a key repeats, the later value wins, and the key keeps the position of its first appearance. Positions follow JavaScript's property order: integer-like keys ("2", "10") always come first in ascending order, then the other strings in the order they first appear, then symbols. So fromPairs([["b", 1], ["2", 2]]) lists "2" before "b".
Keys become property names: numbers turn into strings, and symbols stay symbols.
A pair whose key is "__proto__" makes an ordinary own property named "__proto__"; it never changes the object's prototype.
A pair with no second item gives the value undefined.
It accepts any iterable of pairs, such as a Map. Values are kept as they are, not copied.
toPairs:
It returns [key, value] for each own enumerable string key, in the same order as Object.keys (whole-number keys first, in ascending order, then the others in the order they were added).
It skips inherited properties, non-enumerable properties and symbol keys.
For an array, the keys are the indexes as strings. An empty object gives [].
Both:
fromPairs(toPairs(object)) rebuilds an object with the same own enumerable string keys and values, in the same order. Symbol keys, non-enumerable and inherited properties are not listed by toPairs (rule 8), so they are not rebuilt.
Object.fromEntries and Object.entries are not used.