From 1b1943b0caa7b54d0f6bb1dbba65c7b5439784c9 Mon Sep 17 00:00:00 2001 From: Mike Frawley Date: Wed, 17 Feb 2010 09:53:36 -0600 Subject: [PATCH] implement include in terms of detect --- underscore.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/underscore.js b/underscore.js index 6c9004370..cce9756a4 100644 --- a/underscore.js +++ b/underscore.js @@ -149,15 +149,12 @@ return result; }; - // Determine if a given value is included in the array or object, - // based on '==='. + // Determine if a given value is included in the array or object using '==='. _.include = function(obj, target) { if (obj && _.isFunction(obj.indexOf)) return _.indexOf(obj, target) != -1; - var found = false; - each(obj, function(value) { - if (found = value === target) _.breakLoop(); + return !! _.detect(obj, function(value) { + return value === target; }); - return found; }; // Invoke a method with arguments on every item in a collection.