Skip to content

Commit

Permalink
NaN is never equal to NaN. Fixed in underscore.js and underscore-min.…
Browse files Browse the repository at this point in the history
…js, updated tests in test/objects.js
  • Loading branch information
ryantenney committed Jun 12, 2010
1 parent 79f65b4 commit 0e8ca3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion test/objects.js
Expand Up @@ -54,7 +54,9 @@ $(document).ready(function() {
ok(_.isEqual(moe, clone), 'deep equality is true');
ok(_(moe).isEqual(clone), 'OO-style deep equality works');
ok(!_.isEqual(5, NaN), '5 is not equal to NaN');
ok(_.isEqual(NaN, NaN), 'NaN is equal to NaN');
ok(NaN != NaN, 'NaN is not equal to NaN (native equality)');
ok(NaN !== NaN, 'NaN is not equal to NaN (native identity)');
ok(!_.isEqual(NaN, NaN), 'NaN is not equal to NaN');
ok(_.isEqual(new Date(100), new Date(100)), 'identical dates are equal');
ok(_.isEqual((/hello/ig), (/hello/ig)), 'identical regexes are equal');
ok(!_.isEqual(null, [1]), 'a falsy is never equal to a truthy');
Expand Down
2 changes: 1 addition & 1 deletion underscore-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore.js
Expand Up @@ -469,7 +469,7 @@
// Check dates' integer values.
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
// Both are NaN?
if (_.isNaN(a) && _.isNaN(b)) return true;
if (_.isNaN(a) && _.isNaN(b)) return false;
// Compare regular expressions.
if (_.isRegExp(a) && _.isRegExp(b))
return a.source === b.source &&
Expand Down

0 comments on commit 0e8ca3c

Please sign in to comment.