File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
lib/node_modules/@stdlib/iter/some Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -38,23 +38,27 @@ 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 }
5253 i = - 1 ; // reset index
5354 return {
54- 'value' : arr [ len - 1 ] ,
5555 'done' : true
5656 } ;
5757 }
58+
59+ function reset ( ) {
60+ i = - 1 ;
61+ }
5862}
5963
6064
@@ -73,6 +77,7 @@ bench( pkg, function benchmark( b ) {
7377 if ( ! isBoolean ( bool ) ) {
7478 b . fail ( 'should return a boolean' ) ;
7579 }
80+ arr . reset ( ) ;
7681 }
7782 b . toc ( ) ;
7883 if ( ! isBoolean ( bool ) ) {
@@ -112,6 +117,7 @@ bench( pkg+'::loop', function benchmark( b ) {
112117 if ( ! isBoolean ( bool ) ) {
113118 b . fail ( 'should be a boolean' ) ;
114119 }
120+ arr . reset ( ) ;
115121 }
116122 b . toc ( ) ;
117123 if ( ! isBoolean ( bool ) ) {
Original file line number Diff line number Diff line change @@ -55,17 +55,16 @@ function iterSome( iterator, n ) {
5555 count = 0 ;
5656 while ( true ) {
5757 v = iterator . next ( ) ;
58+ if ( v . done ) {
59+ return false ;
60+ }
5861 if ( v . value ) {
5962 count += 1 ;
6063 if ( count === n ) {
6164 return true ;
6265 }
6366 }
64- if ( v . done ) {
65- break ;
66- }
6767 }
68- return false ;
6968}
7069
7170
You can’t perform that action at this time.
0 commit comments