Skip to content

Commit

Permalink
Modified any/some test case to demonstrate issue jashkenas#177
Browse files Browse the repository at this point in the history
Fixed any/some formatting to be consistent with the rest of underscore.js
  • Loading branch information
shinuza committed May 20, 2011
1 parent 5141a51 commit 40af165
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ $(document).ready(function() {
});

test('collections: any', function() {
var nativeSome = Array.prototype.some;
Array.prototype.some = null;
ok(!_.any([]), 'the empty set');
ok(!_.any([false, false, false]), 'all false values');
ok(_.any([false, false, true]), 'one true value');
ok(!_.any([1, 11, 29], function(num){ return num % 2 == 0; }), 'all odd numbers');
ok(_.any([1, 10, 29], function(num){ return num % 2 == 0; }), 'an even number');
ok(_.some([false, false, true]), 'aliased as "some"');
Array.prototype.some = nativeSome;
});

test('collections: include', function() {
Expand Down
4 changes: 2 additions & 2 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function (value, index, list) {
if (result |= iterator.call(context, value, index, list)) return breaker;
if (result |= iterator.call(context, value, index, list)) return breaker;
});
return !!result;
}
};

// Determine if a given value is included in the array or object using `===`.
// Aliased as `contains`.
Expand Down

0 comments on commit 40af165

Please sign in to comment.