function merge(...args) {
    let output = null,
        items = [...args];
    while (items.length > 0) {
        const nextItem = items.shift();
        if (!output) {
            output = Object.assign({}, nextItem);
        } else {
            output = mergeObjects(output, nextItem);
        }
    }
    return output;
}

function mergeObjects(obj1, obj2) {
    const output = Object.assign({}, obj1);
    Object.keys(obj2).forEach(key => {
        if (!output.hasOwnProperty(key)) {
            output[key] = obj2[key];
            return;
        }
        if (Array.isArray(obj2[key])) {
            output[key] = Array.isArray(output[key]) ? [...output[key], ...obj2[key]] : [...obj2[key]];
        } else if (typeof obj2[key] === "object" && !!obj2[key]) {
            output[key] =
                typeof output[key] === "object" && !!output[key]
                    ? mergeObjects(output[key], obj2[key])
                    : Object.assign({}, obj2[key]);
        } else {
            output[key] = obj2[key];
        }
    });
    return output;
}

module.exports = {
    merge
};

@@ -1,20 +1,131 @@
+function clone(obj) %7B%0A    return Object.setPrototypeOf(Object.assign(%7B%7D, obj), Object.getPrototypeOf(obj));%0A%7D%0A%0A
 function merge(...ar
@@ -126,24 +126,24 @@
 (...args) %7B%0A
-
     let outp
@@ -295,34 +295,22 @@
 utput = 
-Object.assign(%7B%7D, 
+clone(
 nextItem
@@ -475,34 +475,22 @@
 utput = 
-Object.assign(%7B%7D, 
+clone(
 obj1);%0A 
@@ -1020,34 +1020,22 @@
       : 
-Object.assign(%7B%7D, 
+clone(
 obj2%5Bkey

Fix merging objects with prototypes