Skip to content

Commit d4c8254

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

File tree

2 files changed

+9
-79
lines changed

2 files changed

+9
-79
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,26 @@ function iterawln( iterator, sigma, options ) {
240240
* @returns {Object} iterator protocol-compliant object
241241
*/
242242
function next() {
243-
var out;
244243
var v;
245244
if ( FLG ) {
246245
return {
247246
'done': true
248247
};
249248
}
250-
out = {};
251249
v = iterator.next();
252-
if ( typeof v.value === 'number' ) {
253-
out.value = v.value + rlaplace();
254-
} else if ( hasOwnProp( v, 'value' ) ) {
255-
out.value = NaN;
256-
}
257250
if ( v.done ) {
258251
FLG = true;
259-
out.done = true;
252+
return v;
253+
}
254+
if ( typeof v.value === 'number' ) {
255+
v = v.value + rlaplace();
260256
} else {
261-
out.done = false;
257+
v = NaN;
262258
}
263-
return out;
259+
return {
260+
'value': v,
261+
'done': false
262+
};
264263
}
265264

266265
/**

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

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

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

0 commit comments

Comments
 (0)