Skip to content

Commit f2c9c0e

Browse files
authored
docs: update example
Signed-off-by: Athan <[email protected]>
1 parent 29805ed commit f2c9c0e

File tree

1 file changed

+7
-14
lines changed
  • lib/node_modules/@stdlib/stats/incr/nanstdev/examples

1 file changed

+7
-14
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,19 @@
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' );
2223
var incrnanstdev = require( './../lib' );
2324

24-
var accumulator;
25-
var s;
26-
var v;
27-
var i;
28-
2925
// Initialize an accumulator:
30-
accumulator = incrnanstdev();
26+
var accumulator = incrnanstdev();
3127

3228
// For each simulated datum, update the corrected sample standard deviation...
3329
console.log( '\nValue\tSigma\n' );
30+
var v;
31+
var i;
3432
for ( i = 0; i < 100; i++ ) {
35-
if ( randu() < 0.2 ) {
36-
v = NaN;
37-
} else {
38-
v = randu() * 100.0;
39-
}
40-
s = accumulator( v );
41-
console.log( '%d\t%d', v.toFixed( 4 ), s.toFixed( 4 ) );
33+
v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 );
34+
console.log( '%d\t%d', v.toFixed( 4 ), accumulator( v ).toFixed( 4 ) );
4235
}
4336
console.log( '\nFinal standard deviation: %d\n', accumulator() );

0 commit comments

Comments
 (0)