diff --git a/lib/utils.js b/lib/utils.js index cfed4ecd..b9b18cd3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -76,8 +76,9 @@ var merge = function merge(target, source, options) { if (Array.isArray(target) && Array.isArray(source)) { source.forEach(function (item, i) { if (has.call(target, i)) { - if (target[i] && typeof target[i] === 'object' && item && typeof item === 'object') { - target[i] = merge(target[i], item, options); + var targetItem = target[i]; + if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') { + target[i] = merge(targetItem, item, options); } else { target.push(item); } diff --git a/test/utils.js b/test/utils.js index fcd85a01..c3faa704 100644 --- a/test/utils.js +++ b/test/utils.js @@ -39,10 +39,10 @@ test('merge()', function (t) { }); utils.merge(observed, [null]); st.equal(setCount, 0); - st.equal(getCount, 2); + st.equal(getCount, 1); observed[0] = observed[0]; // eslint-disable-line no-self-assign st.equal(setCount, 1); - st.equal(getCount, 3); + st.equal(getCount, 2); st.end(); } );