6 kyu

Dictionary Merge

248 of 1,233Kartoffelsalat

Description:

Your task is to implement a function that takes one or more dictionaries and combines them in one result dictionary.

The keys in the given dictionaries can overlap. In that case you should combine all source values in an array. Duplicate values should be preserved.

Here is an example:

var source1 = new Dictionary<string, int>{{"A", 1}, {"B", 2}}; 
var source2 = new Dictionary<string, int>{{"A", 3}};

Dictionary<string, int[]> result = DictionaryMerger.Merge(source1, source2);
// result should have this content: {{"A", [1, 3]}, {"B", [2]}}
source1 = {"A": 1, "B": 2} 
source2 = {"A": 3}

result = merge(source1, source2);
// result should have this content: {"A": [1, 3]}, "B": [2]}
let source1 = ["A": 1, "B": 2]
let source2 = ["A": 3]

let result = merge([source1, source2])
// result should have this content: ["A": [1, 3], "B": [2]]

You can assume that only valid dictionaries are passed to your function. The number of given dictionaries might be large. So take care about performance.

Fundamentals

More By Author:

Check out these other kata created by Kartoffelsalat

Stats:

CreatedMay 1, 2018
PublishedMay 1, 2018
Warriors Trained2379
Total Skips114
Total Code Submissions4110
Total Times Completed1233
C# Completions248
Python Completions873
Swift Completions124
Total Stars43
% of votes with a positive feedback rating94% of 216
Total "Very Satisfied" Votes192
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes4
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Kartoffelsalat Avatar
  • TellowKrinkle Avatar
  • Voile Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • saudiGuy Avatar
Ad