Skip to content

Commit f718b89

Browse files
committed
Refactor to ignore iterator return values
1 parent 503d531 commit f718b89

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

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

Lines changed: 8 additions & 2 deletions
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 ( isnan( v ) ) {
7478
b.fail( 'should not be NaN' );
7579
}
80+
arr.reset();
7681
}
7782
b.toc();
7883
if ( isnan( v ) ) {
@@ -100,6 +105,7 @@ bench( pkg+'::loop', function benchmark( b ) {
100105
if ( isnan( v ) ) {
101106
b.fail( 'should not be NaN' );
102107
}
108+
arr.reset();
103109
}
104110
b.toc();
105111
if ( isnan( v ) ) {

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

Lines changed: 1 addition & 6 deletions
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 //
@@ -50,14 +49,10 @@ function iterLast( iterator ) {
5049
while ( true ) {
5150
v = iterator.next();
5251
if ( v.done ) {
53-
if ( hasOwnProp( v, 'value' ) ) {
54-
return v.value;
55-
}
56-
break;
52+
return last;
5753
}
5854
last = v.value;
5955
}
60-
return last;
6156
}
6257

6358

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,3 @@ tape( 'the function returns the last iterated value', function test( t ) {
8383
t.strictEqual( v, 1, 'returns expected value' );
8484
t.end();
8585
});
86-
87-
tape( 'the function returns the last iterated value (value+done)', function test( t ) {
88-
var arr;
89-
var v;
90-
91-
arr = createIterator( [ 0, 0, 1 ] );
92-
v = iterLast( arr );
93-
94-
t.strictEqual( v, 1, 'returns expected value' );
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-
var out;
112-
i += 1;
113-
if ( i < len ) {
114-
out = {};
115-
out.value = arr[ i ];
116-
out.done = ( i === len-1 );
117-
return out;
118-
}
119-
return {
120-
'done': true
121-
};
122-
}
123-
}
124-
});

0 commit comments

Comments
 (0)