Created
November 12, 2013 08:10
-
-
Save timoxley/7427294 to your computer and use it in GitHub Desktop.
how to do deep equal on sparse array?
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('assert') | |
| var a = [] | |
| // make sparse array | |
| a[20] = true | |
| var b = [] | |
| // try copying a's items into b with splice | |
| b.splice.apply(b, [0, 0].concat(a.slice(0, 21))) | |
| assert.deepEqual(a, b) // throws? | |
| console.log(b) | |
| /* | |
| [ undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| undefined, | |
| true ] | |
| */ | |
| console.log(a) | |
| /* | |
| [ , , , , , , , , , , , , , , , , , , , , true ] | |
| */ | |
| console.log(a[0] === b[0]) | |
| /* | |
| true | |
| */ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahh, I've got it.
bhas numeric keys 0 - 20.adoes not.assert.deepEqualmust do something related to the keys.