Created
May 20, 2016 02:31
-
-
Save jovey-zheng/81954c696c7f5c4f7953d9a0a0a9efaf to your computer and use it in GitHub Desktop.
merge array based on lodash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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