diff --git a/test/objects.js b/test/objects.js index 5fc4b6a0a..e02a76ae4 100644 --- a/test/objects.js +++ b/test/objects.js @@ -183,7 +183,7 @@ $(document).ready(function() { // Sparse arrays. ok(_.isEqual(Array(3), Array(3)), "Sparse arrays of identical lengths are equal"); - ok(_.isEqual(Array(3), Array(6)), "Sparse arrays of different lengths are equal when both are empty"); + ok(!_.isEqual(Array(3), Array(6)), "Sparse arrays of different lengths are not equal when both are empty"); // According to the Microsoft deviations spec, section 2.1.26, JScript 5.x treats `undefined` // elements in arrays as elisions. Thus, sparse arrays and dense arrays containing `undefined` diff --git a/underscore.js b/underscore.js index 1cb07d815..d219bc206 100644 --- a/underscore.js +++ b/underscore.js @@ -675,6 +675,8 @@ } // Ensure that both values are objects. if (typeA != 'object') return false; + // Arrays or Arraylikes with different lengths are not equal. + if (a.length !== b.length) return false; // Objects with different constructors are not equal. if (a.constructor !== b.constructor) return false; // Assume equality for cyclic structures. The algorithm for detecting cyclic structures is