mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Ensure lazy takeWhile works with reverse and last`. [closes #990]
This commit is contained in:
@@ -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));
|
||||
});
|
||||
};
|
||||
|
||||
14
test/test.js
14
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user