Skip to content

Commit

Permalink
Merge pull request #80 from gerneio/patch-1
Browse files Browse the repository at this point in the history
Aggregate Bug #79
  • Loading branch information
ENikS committed Jan 12, 2019
2 parents bb1984a + 0369611 commit a02192f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/linq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class EnumerableImpl<T> implements Enumerable<T>, Iterable<T>, IEnumerable<T> {
}
let result: A = zero;
for (let value of this) {
if (!result) result = Constant.getDefaultVal(typeof (value));
if ([null, undefined].indexOf(result) > -1 || (isNaN(result as any) && !result))
result = Constant.getDefaultVal(typeof (value));

result = method(result, value);
}
return selector(result);
Expand Down
5 changes: 4 additions & 1 deletion test/immediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe('Immediate Execution -', function () {
it('Aggregate() - Transform', function () {
assert.equal(1814400, Linq.From(simpleArray).Aggregate(1, (a, b) => a * b, o => o / 2));
});


it('Aggregate() - Default Value [String]', function () {
assert.equal("123", Linq.From([1, 2, 3]).Aggregate("", (c, n) => c.toString() + n.toString()));
});


// All
Expand Down

0 comments on commit a02192f

Please sign in to comment.