Skip to content

Commit 045297e

Browse files
committed
changes in index
1 parent e0252d8 commit 045297e

File tree

1 file changed

+11
-7
lines changed
  • lib/node_modules/@stdlib/stats/incr/nanmidrange/examples

1 file changed

+11
-7
lines changed

lib/node_modules/@stdlib/stats/incr/nanmidrange/examples/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/base/uniform' );
22+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2224
var incrnanmidrange = require( './../lib' );
2325

2426
var accumulator;
@@ -29,13 +31,15 @@ var i;
2931
// Initialize an accumulator:
3032
accumulator = incrnanmidrange();
3133

32-
console.log( '\nValue\tMid-range\n' );
33-
3434
// For each simulated datum, update the mid-range...
35+
console.log( '\nValue\tMid-range\n' );
3536
for ( i = 0; i < 100; i++ ) {
36-
v = (randu() < 0.1) ? NaN : randu() * 100.0;
37+
v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 );
3738
midrange = accumulator( v );
38-
console.log( '%d\t%s', v.toFixed( 4 ), (midrange !== null ? midrange.toFixed( 4 ) : 'null') );
39+
if ( midrange === null ) {
40+
console.log( '%d\t%s', v.toFixed( 4 ), midrange );
41+
} else {
42+
console.log( '%d\t%d', ( isnan( v ) ) ? NaN : v.toFixed( 4 ), midrange.toFixed( 4 ) );
43+
}
3944
}
40-
41-
console.log( '\nFinal mid-range: %s\n', (accumulator() !== null ? accumulator().toFixed( 4 ) : 'null') );
45+
console.log( '\nFinal mid-range: %d\n', accumulator() );

0 commit comments

Comments
 (0)