Skip to content

Instantly share code, notes, and snippets.

@jovey-zheng
Created May 20, 2016 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jovey-zheng/81954c696c7f5c4f7953d9a0a0a9efaf to your computer and use it in GitHub Desktop.
Save jovey-zheng/81954c696c7f5c4f7953d9a0a0a9efaf to your computer and use it in GitHub Desktop.
merge array based on lodash.
var _ = require('lodash');
module.exports = function (source, target) {
var joinArrays = function (a, b) {
if (_.isArray(a) && _.isArray(b)) {
return a.concat(b);
};
if (_.isPlainObject(a) && _.isPlainObject(b)) {
return _.merge(a, b, joinArrays);
};
return a;
}
return _.merge(target, source, joinArrays);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment