fix keying of sparse arrays

This commit is contained in:
Conduitry 2018-03-18 03:59:34 -04:00
parent 96e2fd9f48
commit ecd9964a94
2 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,5 @@
let ARRAY = Symbol()
let HOLE = Symbol()
let OBJECT = Symbol()
let REGEXP = Symbol()
let DATE = Symbol()
@ -11,7 +12,7 @@ let recurse = obj => {
switch (typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj)) {
case Array.prototype:
array.push(ARRAY, obj.length)
obj.forEach(recurse)
for (let i = 0; i < obj.length; i++) i in obj ? recurse(obj[i]) : array.push(HOLE)
break
case Object.prototype:
temp = [...Object.getOwnPropertyNames(obj).sort(), ...Object.getOwnPropertySymbols(obj)]

View File

@ -15,6 +15,8 @@ assert.equal(call([]), call([]))
assert.equal(call(a), call([0]))
}
assert.notEqual(call([1, , 2]), call([1, 2, ,])) // eslint-disable-line no-sparse-arrays
assert.equal(call({}), call({}))
{