Skip to content

Commit c55d5c0

Browse files
committed
Refactor to ignore iterator return values
1 parent e4acb57 commit c55d5c0

3 files changed

Lines changed: 8 additions & 45 deletions

File tree

lib/node_modules/@stdlib/iter/nth/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/nth/lib/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
2424
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
25-
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2625

2726

2827
// MAIN //
@@ -58,9 +57,6 @@ function iterNth( iterator, n ) {
5857
i += 1;
5958
v = iterator.next();
6059
if ( v.done ) {
61-
if ( i === n && hasOwnProp( v, 'value' ) ) {
62-
return v.value;
63-
}
6460
return;
6561
}
6662
if ( i === n ) {

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -114,42 +114,3 @@ tape( 'the function returns the nth iterated value', function test( t ) {
114114
t.strictEqual( v, 1, 'returns expected value' );
115115
t.end();
116116
});
117-
118-
tape( 'the function returns the nth iterated value (value+done)', function test( t ) {
119-
var arr;
120-
var v;
121-
122-
arr = createIterator( [ 0, 0, 1 ] );
123-
v = iterNth( arr, 3 );
124-
125-
t.strictEqual( v, 1, 'returns expected value' );
126-
t.end();
127-
128-
function createIterator( arr ) {
129-
var len;
130-
var it;
131-
var i;
132-
133-
len = arr.length;
134-
i = -1;
135-
136-
it = {};
137-
it.next = next;
138-
139-
return it;
140-
141-
function next() {
142-
var out;
143-
i += 1;
144-
if ( i < len ) {
145-
out = {};
146-
out.value = arr[ i ];
147-
out.done = ( i === len-1 );
148-
return out;
149-
}
150-
return {
151-
'done': true
152-
};
153-
}
154-
}
155-
});

0 commit comments

Comments
 (0)