Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Assigning an array shorter than previous one results in merged array #21

Closed
JonnyBurger opened this issue Aug 28, 2016 · 2 comments
Closed

Comments

@JonnyBurger
Copy link

I have encountered this problem when I tried to remove an object from an array and re-assign it to an object.

I have broken down the problem into this simple example:

const deepAssign = require('deep-assign');

const result = deepAssign({}, {
  a: [1, 2]
}, {
  a: [3]
});
console.log(result.a) // => [3, 2]

I expected result.a to be [3] instead.
The native Object.assign from v8 yields a different result:

const result = Object.assign({}, {
  a: [1, 2]
}, {
  a: [3]
});
console.log(result.a) // => [3]

This leads me to believe that this is a bug in deep-assign.

@schnittstabil
Copy link
Contributor

schnittstabil commented Aug 28, 2016

deep-assign is recusive, thus the base case of your example should be:

Object.assign([1, 2], [3])
//=> [ 3, 2 ]

@sindresorhus
Copy link
Owner

This module is now deprecated: b332062

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants