From 1241fb54f3e06a705ac7a09b97b56e29d2745fad Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Tue, 24 Jun 2014 18:26:40 -0400 Subject: [PATCH] Simplify _.*RightWhile loops --- lodash.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lodash.js b/lodash.js index 10878002b..8f6706695 100644 --- a/lodash.js +++ b/lodash.js @@ -2884,14 +2884,11 @@ */ function dropRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0, - index = length, - n = 0; + index = length; predicate = lodash.callback(predicate, thisArg, 3); - while (index-- && predicate(array[index], index, array)) { - n++; - } - return slice(array, 0, length - n); + while (index-- && predicate(array[index], index, array)) { } + return slice(array, 0, index + 1); } /** @@ -3606,14 +3603,11 @@ */ function takeRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0, - index = length, - n = 0; + index = length; predicate = lodash.callback(predicate, thisArg, 3); - while (index-- && predicate(array[index], index, array)) { - n++; - } - return slice(array, length - n); + while (index-- && predicate(array[index], index, array)) { } + return slice(array, index + 1); } /**