Рет қаралды 25
🎯Welcome to Day 81 of the 100 Days of JavaScript Coding Challenge! 🚀
#CodeWithPoonam #100DaysOfCode
📥 Problem Statement:
Write a JavaScript function that merges two objects where values with the same keys are added together.
📊 Example:
Input:
obj1 = { a: 1, b: 2, c: 3 }
obj2 = { a: 3, b: 4, d: 5 }
Output: { a: 4, b: 6, c: 3, d: 5 }
💡 Approach:
✅ Step 1: Use the spread operator to create a copy of the first object (obj1).
✅ Step 2: Loop through the keys of the second object (obj2).
✅ Step 3: For each key, check if it already exists in the result object.
✅ Step 4: If the key exists, add the value to the existing value; otherwise, add the key-value pair from obj2.
✅ Step 5: Return or print the result object
📚 Key Concepts Used:
✅ Spread Operator (...): Used to create a shallow copy of the first object.
✅ For-in Loop: Loops through the keys of the second object.
✅ Conditional (||): Ensures that if the key does not exist in the result, the value is initialized to 0 before addition.
📅 On Day 81,You learned how to merge two objects while summing the values of matching keys. This is useful when you want to combine data from two sources with common keys.
🔥 Keep up the great work!
📩 #JavaScript #CodingChallenge #100DaysOfCode
javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript reduce interview questions, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.#javascriptcoding
javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript strings interview questions answers, javascript object interview questions answers, javascript math interview questions, javascript reduce interview questions, javascript coding interview questions and answers, javascript coding for beginners, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.
Javascript interview questions and answers, javascript interview questions, javascript interview coding exercises, javascript interview questions and answers 2024, javascript interview questions and answers 2023, javascript interview prep, javascript in 12 minutes.