Skip to content

Commit e272317

Browse files
committed
Refactor to ignore iterator return values
1 parent 7462064 commit e272317

File tree

3 files changed

+12
-102
lines changed

3 files changed

+12
-102
lines changed

lib/node_modules/@stdlib/iter/every/benchmark/benchmark.js

+8-2
Original file line numberDiff line numberDiff 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 ) ) {
@@ -104,6 +109,7 @@ bench( pkg+'::loop', function benchmark( b ) {
104109
if ( !isBoolean( bool ) ) {
105110
b.fail( 'should be a boolean' );
106111
}
112+
arr.reset();
107113
}
108114
b.toc();
109115
if ( !isBoolean( bool ) ) {

lib/node_modules/@stdlib/iter/every/lib/main.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
24-
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2524

2625

2726
// MAIN //
@@ -48,20 +47,13 @@ function iterEvery( iterator ) {
4847
}
4948
while ( true ) {
5049
v = iterator.next();
51-
if ( v.value ) {
52-
if ( v.done ) {
53-
break;
54-
}
55-
} else if ( v.done ) {
56-
if ( hasOwnProp( v, 'value' ) ) {
57-
return false;
58-
}
59-
break;
60-
} else {
50+
if ( v.done ) {
51+
return true;
52+
}
53+
if ( !v.value ) {
6154
return false;
6255
}
6356
}
64-
return true;
6557
}
6658

6759

lib/node_modules/@stdlib/iter/every/test/test.js

-88
Original file line numberDiff line numberDiff line change
@@ -84,50 +84,6 @@ tape( 'the function returns `true` if all iterated values are truthy', function
8484
t.end();
8585
});
8686

87-
tape( 'the function returns `true` if all iterated values are truthy (value+done)', function test( t ) {
88-
var bool;
89-
var arr;
90-
91-
arr = createIterator( [ 1, 1, 1, 1 ] );
92-
bool = iterEvery( arr );
93-
94-
t.strictEqual( bool, true, 'returns true' );
95-
t.end();
96-
97-
function createIterator( arr ) {
98-
var len;
99-
var it;
100-
var i;
101-
102-
len = arr.length;
103-
i = -1;
104-
105-
it = {};
106-
it.next = next;
107-
108-
return it;
109-
110-
function next() {
111-
i += 1;
112-
if ( i < len-1 ) {
113-
return {
114-
'value': arr[ i ],
115-
'done': false
116-
};
117-
}
118-
if ( i === len-1 ) {
119-
return {
120-
'value': arr[ i ],
121-
'done': true
122-
};
123-
}
124-
return {
125-
'done': true
126-
};
127-
}
128-
}
129-
});
130-
13187
tape( 'the function returns `false` if at least one iterated value is falsy', function test( t ) {
13288
var bool;
13389
var arr;
@@ -138,47 +94,3 @@ tape( 'the function returns `false` if at least one iterated value is falsy', fu
13894
t.strictEqual( bool, false, 'returns false' );
13995
t.end();
14096
});
141-
142-
tape( 'the function returns `false` if at least one iterated value is falsy (value+done)', function test( t ) {
143-
var bool;
144-
var arr;
145-
146-
arr = createIterator( [ 1, 1, 1, 0 ] );
147-
bool = iterEvery( arr );
148-
149-
t.strictEqual( bool, false, 'returns false' );
150-
t.end();
151-
152-
function createIterator( arr ) {
153-
var len;
154-
var it;
155-
var i;
156-
157-
len = arr.length;
158-
i = -1;
159-
160-
it = {};
161-
it.next = next;
162-
163-
return it;
164-
165-
function next() {
166-
i += 1;
167-
if ( i < len-1 ) {
168-
return {
169-
'value': arr[ i ],
170-
'done': false
171-
};
172-
}
173-
if ( i === len-1 ) {
174-
return {
175-
'value': arr[ i ],
176-
'done': true
177-
};
178-
}
179-
return {
180-
'done': true
181-
};
182-
}
183-
}
184-
});

0 commit comments

Comments
 (0)