File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
lib/node_modules/@stdlib/stats/iter/sumabs2 Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -38,23 +38,26 @@ function createIterator( arr ) {
3838
3939 it = { } ;
4040 it . next = next ;
41+ it . reset = reset ;
4142
4243 return it ;
4344
4445 function next ( ) {
4546 i += 1 ;
46- if ( i < len - 1 ) {
47+ if ( i < len ) {
4748 return {
4849 'value' : arr [ i ] ,
4950 'done' : false
5051 } ;
5152 }
52- i = - 1 ; // reset index
5353 return {
54- 'value' : arr [ len - 1 ] ,
5554 'done' : true
5655 } ;
5756 }
57+
58+ function reset ( ) {
59+ i = - 1 ;
60+ }
5861}
5962
6063
@@ -73,6 +76,7 @@ bench( pkg, function benchmark( b ) {
7376 if ( isnan ( v ) ) {
7477 b . fail ( 'should not return NaN' ) ;
7578 }
79+ arr . reset ( ) ;
7680 }
7781 b . toc ( ) ;
7882 if ( isnan ( v ) ) {
Original file line number Diff line number Diff line change 2121// MODULES //
2222
2323var isIteratorLike = require ( '@stdlib/assert/is-iterator-like' ) ;
24- var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
2524var incrsumabs2 = require ( '@stdlib/stats/incr/sumabs2' ) ;
2625var format = require ( '@stdlib/string/format' ) ;
2726
@@ -54,14 +53,14 @@ function itersumabs2( iterator ) {
5453 acc = incrsumabs2 ( ) ;
5554 while ( true ) {
5655 v = iterator . next ( ) ;
56+ if ( v . done ) {
57+ break ;
58+ }
5759 if ( typeof v . value === 'number' ) {
5860 acc ( v . value ) ;
59- } else if ( hasOwnProp ( v , 'value' ) ) {
61+ } else {
6062 acc ( NaN ) ;
6163 }
62- if ( v . done ) {
63- break ;
64- }
6564 }
6665 return acc ( ) ;
6766}
You can’t perform that action at this time.
0 commit comments