Skip to content

Commit 6b6a6b7

Browse files
committed
Refactor to ignore iterator return values
1 parent acb65fc commit 6b6a6b7

File tree

2 files changed

+9
-79
lines changed

2 files changed

+9
-79
lines changed

lib/node_modules/@stdlib/simulate/iter/awgn/lib/main.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,26 @@ function iterawgn( iterator, sigma, options ) {
219219
* @returns {Object} iterator protocol-compliant object
220220
*/
221221
function next() {
222-
var out;
223222
var v;
224223
if ( FLG ) {
225224
return {
226225
'done': true
227226
};
228227
}
229-
out = {};
230228
v = iterator.next();
231-
if ( typeof v.value === 'number' ) {
232-
out.value = v.value + ( sigma*rnorm() );
233-
} else if ( hasOwnProp( v, 'value' ) ) {
234-
out.value = NaN;
235-
}
236229
if ( v.done ) {
237230
FLG = true;
238-
out.done = true;
231+
return v;
232+
}
233+
if ( typeof v.value === 'number' ) {
234+
v = v.value + ( sigma*rnorm() );
239235
} else {
240-
out.done = false;
236+
v = NaN;
241237
}
242-
return out;
238+
return {
239+
'value': v,
240+
'done': false
241+
};
243242
}
244243

245244
/**

lib/node_modules/@stdlib/simulate/iter/awgn/test/test.js

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -496,75 +496,6 @@ tape( 'the function supports providing a seeded pseudorandom number generator fo
496496
t.end();
497497
});
498498

499-
tape( 'the function returns an iterator protocol-compliant object which iteratively introduces additive white Gaussian noise (value+done)', function test( t ) {
500-
var expected;
501-
var actual;
502-
var values;
503-
var rnorm;
504-
var it;
505-
var v;
506-
var i;
507-
508-
rnorm = improvedZiggurat.factory({
509-
'seed': 12345
510-
});
511-
512-
values = [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ];
513-
514-
expected = [];
515-
for ( i = 0; i < values.length; i++ ) {
516-
expected.push( values[i] + (1.0*rnorm()) );
517-
}
518-
519-
it = iterawgn( createIterator( values ), 1.0, {
520-
'seed': 12345
521-
});
522-
t.equal( it.next.length, 0, 'has zero arity' );
523-
524-
actual = [];
525-
for ( i = 0; i < values.length; i++ ) {
526-
v = it.next();
527-
t.equal( typeof v.value, 'number', 'returns a number' );
528-
t.equal( typeof v.done, 'boolean', 'returns a boolean' );
529-
actual.push( v.value );
530-
}
531-
t.deepEqual( actual, expected, 'returns expected values' );
532-
533-
v = it.next();
534-
t.equal( v.value, void 0, 'returns expected value' );
535-
t.equal( v.done, true, 'returns expected value' );
536-
537-
t.end();
538-
539-
function createIterator( arr ) {
540-
var len;
541-
var it;
542-
var i;
543-
544-
len = arr.length;
545-
i = -1;
546-
547-
it = {};
548-
it.next = next;
549-
550-
return it;
551-
552-
function next() {
553-
var out;
554-
i += 1;
555-
if ( i < len ) {
556-
out = {};
557-
out.value = arr[ i ];
558-
out.done = ( i === len-1 );
559-
return out;
560-
}
561-
return {
562-
'done': true
563-
};
564-
}
565-
}
566-
});
567-
568499
tape( 'if an iterated value is a non-numeric value, the returned value is `NaN`', function test( t ) {
569500
var values;
570501
var it;

0 commit comments

Comments
 (0)