Skip to content

Commit

Permalink
lodash#274 Fix bug with filtering limited collection. Renamed 'o.fini…
Browse files Browse the repository at this point in the history
…shed' to 'o.running'.
  • Loading branch information
FilipZawada committed Aug 5, 2014
1 parent 5b3a490 commit 19b828a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lodash.js
Expand Up @@ -4427,7 +4427,7 @@
count = count || 1;

this.funcs.push(function (o) {
return (o.finished = (--count <= 0))
return (o.running = (--count > 0));
});

if(this.filterApplied) {
Expand Down Expand Up @@ -4468,17 +4468,17 @@
source = this.source,
dir = this.dir,
result = [],
o = {},
o = { running: true },
resultIndex = 0,
min = this.min,
max = this.max,
sourceIndex = (dir == 1 ? min : max);

while(!o.finished && sourceIndex >= min && sourceIndex <= max)
while(o.running && sourceIndex >= min && sourceIndex <= max)
{
o.value = source[sourceIndex];
o.accepted = true;
o.finished = false;
o.running = true;

sourceIndex += dir;

Expand Down
9 changes: 9 additions & 0 deletions test/test-lazy.js
Expand Up @@ -640,6 +640,7 @@
QUnit.module('lodash.lazy.value');

(function() {
function isEven(x) { return x % 2 == 0; }

test("should return original collection", 1, function() {
var collection = [1, 2, 3];
Expand Down Expand Up @@ -693,6 +694,14 @@

deepEqual(actual, [2, 4]);
});

test("should filter already limited collection", 1, function () {
var collection = [1, 2, 3, 4];

var actual = _.lazy(collection).take(2).filter(isEven).value()

deepEqual(actual, [2]);
});
})();


Expand Down

0 comments on commit 19b828a

Please sign in to comment.