Javascript: Merging dictionaries

JS: Functions
Last update: 13 Sep 23:16
0
Students

dictionary.js

Implement and export as default a function that merges several dictionaries (objects) into a single dictionary. The function takes any number of arguments and returns an object in which each key contains a list of unique values as an array. The items in the list are arranged in the order in which they appear in the given dictionaries.

Examples:

merge({}, {}, {});
// {}

merge({ a: 1, b: 2 }, { a: 3 });
// { a: [1, 3], b: [2] }

merge(
    { a: 1, b: 2, c: 3 },
    {},
    { a: 3, b: 2, d: 5 },
    { a: 6 },
    { b: 4, c: 3, d: 2 },
    { e: 9 },
  );
// { a: [1, 3, 6], b: [2, 4], c: [3], d: [5, 2], e: [9] }

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests