Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison between uninitialized arrays fail #62

Open
omarjackman opened this issue Nov 1, 2018 · 3 comments
Open

Comparison between uninitialized arrays fail #62

omarjackman opened this issue Nov 1, 2018 · 3 comments

Comments

@omarjackman
Copy link

Performing a deep equal on an uninitialized array doesn't behave as expected.

      const myTestArray1 = [undefined, 'test']
      const myTestArray2 = []
      // myTestArray2[0] should be equal to undefined by default
      myTestArray2[1] = 'test'

      expect(myTestArray1).to.deep.equal(myTestArray2)

I would expect these two arrays to pass a deep equality check since javascript seems to default uninitialized values to undefined

@omarjackman omarjackman changed the title Comparison between uninitialized arrays fails Comparison between uninitialized arrays fail Nov 1, 2018
@omarjackman
Copy link
Author

screen shot 2018-11-01 at 11 13 51 am

Just looking at chrome dev console it shows something called empty but I couldn't find any documentation on what that is but I'm guessing its related to this issue

@omarjackman
Copy link
Author

workaround is to use

expect(lodashIsEqual(myTestArray1, myTestArray2)).to.be.true

@andrew1007
Copy link

The concept of an index being empty and undefined are two distinct concepts. undefined is considered an actual entry in specific index, but empty denotes nothing. JavaScript utilizes sparse arrays https://www.oreilly.com/library/view/javascript-the-definitive/9781449393854/ch07s03.html

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

No branches or pull requests

2 participants