Implement a deepMerge function
In JavaScript, merging typically refers to combining two or more objects or arrays into a single object or array. This process is commonly used when you want to consolidate data from multiple sources or update an object with new properties.
1. Basic implementation
We have to implement a deepMerge()
utility function which can merge nested objects and arrays. If same keys exist on both objects and hold a primitive value, simply return the value from second object as the final result.
In the above implementation , I have used a utility called isPojo()
, which essentially checks if the given value is a Plain Old JavaScript Object or not. You can learn more about it’s implementation in the deepEqual function implementation from the Recursion Questions for Frontend Interviews blog series.
Further Reading
I strongly encourage you to explore and tackle additional questions in my Recursion Questions for Frontend Interviews blog series.
By doing so, you can enhance your understanding and proficiency with recursion, preparing you to excel in your upcoming frontend interviews.
Wishing you best. Happy Interviewing 🫡.