diff --git a/lodash.src.js b/lodash.src.js index 64acee3c9..70c18c009 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -11437,7 +11437,7 @@ filtered = result.__filtered__, iteratees = result.__iteratees__ || (result.__iteratees__ = []); - result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0); + result.__filtered__ = filtered || isFilter || isWhile; iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index }); return result; }; @@ -11504,9 +11504,14 @@ }; LazyWrapper.prototype.dropWhile = function(predicate, thisArg) { - var done; + var done, + lastIndex, + isRight = this.__dir__ < 0; + predicate = getCallback(predicate, thisArg, 3); return this.filter(function(value, index, array) { + done = done && (isRight ? index < lastIndex : index > lastIndex); + lastIndex = index; return done || (done = !predicate(value, index, array)); }); }; diff --git a/test/test.js b/test/test.js index 4956159a1..f946040d7 100644 --- a/test/test.js +++ b/test/test.js @@ -3971,17 +3971,18 @@ deepEqual(_.dropWhile(objects, 'b'), objects.slice(2)); }); - test('should return a wrapped value when chaining', 2, function() { + test('should work in a lazy chain sequence', 3, function() { if (!isNpm) { var wrapped = _(array).dropWhile(function(num) { return num < 3; }); - ok(wrapped instanceof _); deepEqual(wrapped.value(), [3, 4]); + deepEqual(wrapped.reverse().value(), [4, 3]); + strictEqual(wrapped.last(), 4); } else { - skipTest(2); + skipTest(3); } }); @@ -4856,17 +4857,18 @@ deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2)); }); - test('should return a wrapped value when chaining', 2, function() { + test('should work in a lazy chain sequence', 3, function() { if (!isNpm) { var wrapped = _(array).takeWhile(function(num) { return num < 3; }); - ok(wrapped instanceof _); deepEqual(wrapped.value(), [1, 2]); + deepEqual(wrapped.reverse().value(), [2, 1]); + strictEqual(wrapped.last(), 2); } else { - skipTest(2); + skipTest(3); } });