Last active
November 2, 2021 07:50
-
-
Save xiongchengqing/95b80020ff859a640d85e8aacc36fea3 to your computer and use it in GitHub Desktop.
Merge
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
import mergeWith from 'lodash/mergeWith' | |
const m1 = { a: 1, b: 2 } | |
const m2 = { a: 9, c: 3 } | |
const m3 = { a: 4, b: 5, d: 7 } | |
// Lodash version | |
// merge objects with customizer | |
mergeWith(m1, m2, m3, (objValue, srcValue, key, object) => { | |
if (Object.prototype.hasOwnProperty.call(object, key)) { | |
return Array.isArray(objValue) ? [...objValue, srcValue] : [objValue, srcValue] | |
} else { | |
return srcValue | |
} | |
}) // ? | |
// Two pointer version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment