mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
_.isEqual: Ensure that an egal comparison is performed for number objects and primitives.
This commit is contained in:
@@ -106,6 +106,8 @@ $(document).ready(function() {
|
||||
ok(_.isEqual(new Number(75), new Number(75)), "Number objects with identical primitive values are equal");
|
||||
ok(_.isEqual(75, new Number(75)), "Number primitives and their corresponding object wrappers are equal");
|
||||
ok(_.isEqual(new Number(75), 75), "Commutative equality is implemented for number objects and primitives");
|
||||
ok(!_.isEqual(new Number(0), -0), "`new Number(0)` and `-0` are not equal");
|
||||
ok(!_.isEqual(0, new Number(-0)), "Commutative equality is implemented for `new Number(0)` and `-0`");
|
||||
|
||||
ok(!_.isEqual(new Number(75), new Number(63)), "Number objects with different primitive values are not equal");
|
||||
ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), "Number objects and objects with a `valueOf` method are not equal");
|
||||
|
||||
@@ -684,14 +684,16 @@
|
||||
// equivalent to `new String("5")`.
|
||||
return String(a) == String(b);
|
||||
case '[object Number]':
|
||||
case '[object Boolean]':
|
||||
// Coerce numbers, dates, and booleans to numeric primitive values.
|
||||
a = +a;
|
||||
b = +b;
|
||||
// `NaN`s are equivalent, but non-reflexive.
|
||||
return a != a ? b != b : a == b;
|
||||
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
|
||||
// other numeric values.
|
||||
return a != a ? b != b : (a == 0 ? 1 / a == 1 / b : a == b);
|
||||
case '[object Date]':
|
||||
// Compare dates by their millisecond representations. Invalid dates are not equivalent.
|
||||
case '[object Boolean]':
|
||||
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
||||
// millisecond representations. Note that invalid dates with millisecond representations
|
||||
// of `NaN` are not equivalent.
|
||||
return +a == +b;
|
||||
// RegExps are compared by their source patterns and flags.
|
||||
case '[object RegExp]':
|
||||
|
||||
Reference in New Issue
Block a user