Skip to content

Commit 8751ab3

Browse files
committed
Refactor to ignore iterator return value
1 parent 0956d9e commit 8751ab3

4 files changed

Lines changed: 17 additions & 75 deletions

File tree

lib/node_modules/@stdlib/stats/iter/mmax/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ var it = itermmax( rand, 3 );
108108
var v;
109109
while ( true ) {
110110
v = it.next();
111-
if ( typeof v.value === 'number' ) {
112-
console.log( 'max: %d', v.value );
113-
}
114111
if ( v.done ) {
115112
break;
116113
}
114+
if ( typeof v.value === 'number' ) {
115+
console.log( 'max: %d', v.value );
116+
}
117117
}
118118
```
119119

lib/node_modules/@stdlib/stats/iter/mmax/examples/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var it = itermmax( rand, 3 );
3434
var v;
3535
while ( true ) {
3636
v = it.next();
37-
if ( typeof v.value === 'number' ) {
38-
console.log( 'max: %d', v.value );
39-
}
4037
if ( v.done ) {
4138
break;
4239
}
40+
if ( typeof v.value === 'number' ) {
41+
console.log( 'max: %d', v.value );
42+
}
4343
}

lib/node_modules/@stdlib/stats/iter/mmax/lib/main.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-propert
2424
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
2525
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
2626
var isFunction = require( '@stdlib/assert/is-function' );
27-
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2827
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
2928
var incrmmax = require( '@stdlib/stats/incr/mmax' );
3029
var format = require( '@stdlib/string/format' );
@@ -91,27 +90,28 @@ function itermmax( iterator, W ) {
9190
* @returns {Object} iterator protocol-compliant object
9291
*/
9392
function next() {
94-
var out;
9593
var v;
9694
if ( FLG ) {
9795
return {
9896
'done': true
9997
};
10098
}
101-
out = {};
10299
v = iterator.next();
103-
if ( typeof v.value === 'number' ) {
104-
out.value = acc( v.value );
105-
} else if ( hasOwnProp( v, 'value' ) ) {
106-
out.value = acc( NaN );
107-
}
108100
if ( v.done ) {
109101
FLG = true;
110-
out.done = true;
102+
return {
103+
'done': true
104+
};
105+
}
106+
if ( typeof v.value === 'number' ) {
107+
v = acc( v.value );
111108
} else {
112-
out.done = false;
109+
v = acc( NaN );
113110
}
114-
return out;
111+
return {
112+
'value': v,
113+
'done': false
114+
};
115115
}
116116

117117
/**

lib/node_modules/@stdlib/stats/iter/mmax/test/test.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -125,64 +125,6 @@ tape( 'the function returns an iterator protocol-compliant object which iterativ
125125
t.end();
126126
});
127127

128-
tape( 'the function returns an iterator protocol-compliant object which iteratively computes a moving maximum value (value+done)', function test( t ) {
129-
var expected;
130-
var actual;
131-
var values;
132-
var it;
133-
var v;
134-
var i;
135-
136-
values = [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ];
137-
expected = [ 2.0, 3.0, 3.0, 4.0, 4.0, 4.0 ];
138-
139-
it = itermmax( createIterator( values ), 3 );
140-
t.equal( it.next.length, 0, 'has zero arity' );
141-
142-
actual = [];
143-
for ( i = 0; i < values.length; i++ ) {
144-
v = it.next();
145-
t.equal( typeof v.value, 'number', 'returns a number' );
146-
t.equal( typeof v.done, 'boolean', 'returns a boolean' );
147-
actual.push( v.value );
148-
}
149-
t.deepEqual( actual, expected, 'returns expected values' );
150-
151-
v = it.next();
152-
t.equal( v.value, void 0, 'returns expected value' );
153-
t.equal( v.done, true, 'returns expected value' );
154-
155-
t.end();
156-
157-
function createIterator( arr ) {
158-
var len;
159-
var it;
160-
var i;
161-
162-
len = arr.length;
163-
i = -1;
164-
165-
it = {};
166-
it.next = next;
167-
168-
return it;
169-
170-
function next() {
171-
var out;
172-
i += 1;
173-
if ( i < len ) {
174-
out = {};
175-
out.value = arr[ i ];
176-
out.done = ( i === len-1 );
177-
return out;
178-
}
179-
return {
180-
'done': true
181-
};
182-
}
183-
}
184-
});
185-
186128
tape( 'if an iterated value is a non-numeric value, the computed maximum value is `NaN` for at least `W` invocations', function test( t ) {
187129
var expected;
188130
var values;

0 commit comments

Comments
 (0)