All files index.js

92.85% Statements 13/14
80% Branches 8/10
100% Functions 3/3
92.85% Lines 13/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x 1x 1x     3x 5x 3x   2x     2x   3x     1x 1x     1x
const isArray = require('lodash/isArray');
const mergeWith = require('lodash/mergeWith');
const isPlainObject = require('lodash/isPlainObject');
const union = require('lodash/union');
 
function mergeArrays(source, target, noDuplicates) {
  const joinArrays = function (a, b) {
    if (isArray(a) && isArray(b)) {
      return noDuplicates === true ? union(a.concat(b)) : a.concat(b);
    };
    Iif (isPlainObject(a) && isPlainObject(b)) {
      return mergeWith(a, b, joinArrays);
    };
    return a;
  }
  return mergeWith(target, source, joinArrays);
}
 
mergeArrays.noDuplicates = function(source, target){
  return mergeArrays(source, target, true);
}
 
module.exports = mergeArrays