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

eql does not work if an array item is undefined in IE8 #140

Open
roberttod opened this issue Aug 12, 2015 · 1 comment
Open

eql does not work if an array item is undefined in IE8 #140

roberttod opened this issue Aug 12, 2015 · 1 comment

Comments

@roberttod
Copy link

The following test fails

describe('eql', function () {
  it('should not remove undefined', function () {
    var arr = []
    arr.push('1')
    arr.push('2')
    arr.push(undefined)
    expect(arr).to.eql(['1', '2', undefined])
  })
})

This is because the keys function used here will not iterate over an undefined array item in IE8 unless the value was pushed to the array.

If on line 941 the keys function is called on a duplicate of the array, this could be resolved.

try{
  var ka, kb, key, i;
  if (isArray(a) && isArray(b)) {
    ka = keys(cloneArray(a));
    kb = keys(cloneArray(b));
  } else {
    ka = keys(a);
    kb = keys(b);
  }
} catch (e) {//happens when one is a string literal and the other isn't
  return false;
}

function cloneArray (arr) {
  var clone = [];
  for (var i = 0; i < arr.length; i++) {
    clone.push(arr[i]);
  }
  return clone;
}

function isArray (obj) {
  return Object.prototype.toString.call(obj) === '[object Array]';
}
@JakeChampion
Copy link

I've ran into this myself just now. I decided to create a separate compare Arrays function.

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