Skip to content
Browse files

use till internally to optimize _.contains and _.every

  • Loading branch information...
1 parent adc778a commit 608ab7143f8681b6cc7c4bf79dc5e51fd99be3bc @clottes committed Feb 8, 2013
Showing with 9 additions and 2 deletions.
  1. +9 −2 underscore.js
View
11 underscore.js
@@ -643,13 +643,15 @@ var till = _.till = _.until = function(obj, iterator, context, pass) {
// Aliased as `all`.
_.every = _.all = function(obj, iterator, context) {
iterator || (iterator = _.identity);
- var result = true;
- if (obj == null) return result;
+ if (obj == null) return true;
if (obj.every === nativeEvery) return obj.every(iterator, context);
+ return till(obj, interator, context, true);
+/*
each(obj, function(value, index, list) {
if (!(result = result && iterator.call(context, value, index, list))) return breaker;
});
return !!result;
+*/
};
// Determine if at least one element in the object matches a truth test.
@@ -671,9 +673,14 @@ var till = _.till = _.until = function(obj, iterator, context, pass) {
_.contains = _.include = function(obj, target) {
if (obj == null) return false;
if (obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
+ return !till(obj,function(value){
+ return value !== target;
+ }, undefined, true);
+/*
return any(obj, function(value) {
return value === target;
});
+*/
};
// Invoke a method (with arguments) on every item in a collection.

0 comments on commit 608ab71

Please sign in to comment.
Something went wrong with that request. Please try again.