Build an object from keys and values
Parsing a CSV gives you one array of column names and one array of cell values per row. Pairing them up by position is what turns two arrays into a usable record.
Implement zipObject(keys, values). Pair keys[i] with values[i] and return a plain object. Extra values beyond the end of keys are ignored. A key with no matching value — that is, an index at or past the end of values — is skipped entirely and must not appear in the result. If the same key appears twice in keys, the later value wins. Keys become object properties, so they are coerced to strings. Two empty arrays return an empty object.
What it has to do
- Pair keys and values by index.
- Ignore values beyond the end of the keys array.
- Skip keys that have no matching value, rather than storing
undefined. - Let the later value win when a key repeats.
- Return
{}when both inputs are empty.
Your workspace
Ready to check it?
5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.
Stuck? The javascript course covers everything this challenge needs.