7 kyu

Combine objects

957 of 9,436matthewglover

Description:

Your task is to write a function that takes two or more objects and returns a new object which combines all the input objects.

All input object properties will have only numeric values. Objects are combined together so that the values of matching keys are added together.

An example:

const objA = { a: 10, b: 20, c: 30 }
const objB = { a: 3, c: 6, d: 3 }
combine(objA, objB) // Returns { a: 13, b: 20, c: 36, d: 3 }
objA = { 'a': 10, 'b': 20, 'c': 30 }
objB = { 'a': 3, 'c': 6, 'd': 3 }
combine(objA, objB) # Returns { a: 13, b: 20, c: 36, d: 3 }
objA = { 'a' => 10, 'b' => 20, 'c' => 30 }
objB = { 'a' => 3, 'c' => 6, 'd' => 3 }
combine(objA, objB) # Returns { a => 13, b => 20, c => 36, d => 3 }

The combine function should be a good citizen, so should not mutate the input objects.

Arrays
Fundamentals

More By Author:

Check out these other kata created by matthewglover

Stats:

CreatedFeb 12, 2016
PublishedFeb 12, 2016
Warriors Trained13351
Total Skips140
Total Code Submissions24728
Total Times Completed9436
JavaScript Completions8361
Python Completions957
Ruby Completions191
Total Stars154
% of votes with a positive feedback rating88% of 630
Total "Very Satisfied" Votes517
Total "Somewhat Satisfied" Votes78
Total "Not Satisfied" Votes35
Ad
Contributors
  • matthewglover Avatar
  • GiacomoSorbi Avatar
  • Blind4Basics Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad