From f64b8e822266200af00fd44c57a1757181eb0f28 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Wed, 30 Oct 2019 14:38:39 +0100 Subject: [PATCH 1/2] Wrong value for _.isEqual(0, new Number(Number.MIN_VALUE)) --- test/objects.js | 1 + underscore.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/objects.js b/test/objects.js index 8e86aac27..356b54eb9 100644 --- a/test/objects.js +++ b/test/objects.js @@ -330,6 +330,7 @@ assert.ok(!_.isEqual(-0, 0), 'Commutative equality is implemented for `0` and `-0`'); assert.ok(!_.isEqual(null, void 0), '`null` is not equal to `undefined`'); assert.ok(!_.isEqual(void 0, null), 'Commutative equality is implemented for `null` and `undefined`'); + assert.ok(!_.isEqual(0, new Number(Number.MIN_VALUE)), '`0` is not equal to `new Number(Number.MIN_VALUE)`'); // String object and primitive comparisons. assert.ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equal'); diff --git a/underscore.js b/underscore.js index 8219dc508..46acc5a70 100644 --- a/underscore.js +++ b/underscore.js @@ -1223,7 +1223,7 @@ // Object(NaN) is equivalent to NaN. if (+a !== +a) return +b !== +b; // An `egal` comparison is performed for other numeric values. - return +a === 0 ? 1 / +a === 1 / b : +a === +b; + return +a === 0 && +b === 0 ? 1 / +a === 1 / b : +a === +b; case '[object Date]': case '[object Boolean]': // Coerce dates and booleans to numeric primitive values. Dates are compared by their From b305986fe246276ab1ea8117a17b06e5538d9b97 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Fri, 10 Apr 2020 20:22:16 +0200 Subject: [PATCH 2/2] Update test/objects.js Co-Authored-By: Julian Gonggrijp --- test/objects.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/objects.js b/test/objects.js index 356b54eb9..651cd3e0e 100644 --- a/test/objects.js +++ b/test/objects.js @@ -331,6 +331,7 @@ assert.ok(!_.isEqual(null, void 0), '`null` is not equal to `undefined`'); assert.ok(!_.isEqual(void 0, null), 'Commutative equality is implemented for `null` and `undefined`'); assert.ok(!_.isEqual(0, new Number(Number.MIN_VALUE)), '`0` is not equal to `new Number(Number.MIN_VALUE)`'); + assert.ok(!_.isEqual(new Number(Number.MIN_VALUE), 0), '`new Number(Number.MIN_VALUE)` is not equal to `0`'); // String object and primitive comparisons. assert.ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equal');