Skip to content

Commit

Permalink
refactoring reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 15, 2021
1 parent a73f0ab commit 4f5a38b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ops/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export function reduce<T>(cb: (previousValue: T, currentValue: T, index: number)
let done = false;
return {
next(): IteratorResult<T> {
let value;
if (done) {
return {value: undefined, done};
return {value, done};
}
let index = 0, value = initialValue as T;
let index = 0;
value = initialValue as T;
for (const curr of iterator) {
if (!index++ && value === undefined) {
value = curr;
Expand Down

0 comments on commit 4f5a38b

Please sign in to comment.