Skip to content

Commit 75cbf89

Browse files
hrshyastdlib-bot
andauthored
chore: replace manual for loop in examples
PR-URL: #6308 Co-authored-by: stdlib-bot <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Karan Anand <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 442efb4 commit 75cbf89

File tree

16 files changed

+130
-146
lines changed

16 files changed

+130
-146
lines changed

lib/node_modules/@stdlib/math/base/special/besselj0/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ v = j0( NaN );
8383
<!-- eslint no-undef: "error" -->
8484

8585
```javascript
86-
var randu = require( '@stdlib/random/base/randu' );
87-
var j0 = require( '@stdlib/math/base/special/besselj0' );
86+
var uniform = require( '@stdlib/random/array/uniform' );
87+
var logEachMap = require( '@stdlib/console/log-each-map' );
88+
var besselj0 = require( '@stdlib/math/base/special/besselj0' );
8889

89-
var x;
90-
var i;
90+
var opts = {
91+
'dtype': 'float64'
92+
};
93+
var x = uniform( 100, 0.0, 100.0, opts );
9194

92-
for ( i = 0; i < 100; i++ ) {
93-
x = randu() * 10.0;
94-
console.log( 'j0(%d) = %d', x, j0( x ) );
95-
}
95+
logEachMap( 'besselj0(%0.4f) = %0.4f', x, besselj0 );
9696
```
9797

9898
</section>

lib/node_modules/@stdlib/math/base/special/besselj0/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var besselj0 = require( './../lib' );
2324

24-
var x;
25-
var i;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var x = uniform( 100, 0.0, 100.0, opts );
2629

27-
for ( i = 0; i < 100; i++ ) {
28-
x = randu() * 100.0;
29-
console.log( 'besselj0(%d) = %d', x, besselj0( x ) );
30-
}
30+
logEachMap( 'besselj0(%0.4f) = %0.4f', x, besselj0 );

lib/node_modules/@stdlib/math/base/special/besselj1/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ v = j1( NaN );
8383
<!-- eslint no-undef: "error" -->
8484

8585
```javascript
86-
var randu = require( '@stdlib/random/base/randu' );
87-
var j1 = require( '@stdlib/math/base/special/besselj1' );
86+
var uniform = require( '@stdlib/random/array/uniform' );
87+
var logEachMap = require( '@stdlib/console/log-each-map' );
88+
var besselj1 = require( '@stdlib/math/base/special/besselj1' );
8889

89-
var x;
90-
var i;
90+
var opts = {
91+
'dtype': 'float64'
92+
};
93+
var x = uniform( 100, 0.0, 100.0, opts );
9194

92-
for ( i = 0; i < 100; i++ ) {
93-
x = randu() * 10.0;
94-
console.log( 'j1(%d) = %d', x, j1( x ) );
95-
}
95+
logEachMap( 'besselj1(%0.4f) = %0.4f', x, besselj1 );
9696
```
9797

9898
</section>

lib/node_modules/@stdlib/math/base/special/besselj1/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var besselj1 = require( './../lib' );
2324

24-
var x;
25-
var i;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var x = uniform( 100, 0.0, 100.0, opts );
2629

27-
for ( i = 0; i < 100; i++ ) {
28-
x = randu() * 100.0;
29-
console.log( 'besselj1(%d) = %d', x, besselj1( x ) );
30-
}
30+
logEachMap( 'besselj1(%0.4f) = %0.4f', x, besselj1 );

lib/node_modules/@stdlib/math/base/special/bessely0/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ v = y0( NaN );
9090
<!-- eslint no-undef: "error" -->
9191

9292
```javascript
93-
var randu = require( '@stdlib/random/base/randu' );
94-
var y0 = require( '@stdlib/math/base/special/bessely0' );
93+
var uniform = require( '@stdlib/random/array/uniform' );
94+
var logEachMap = require( '@stdlib/console/log-each-map' );
95+
var bessely0 = require( '@stdlib/math/base/special/bessely0' );
9596

96-
var x;
97-
var i;
97+
var opts = {
98+
'dtype': 'float64'
99+
};
100+
var x = uniform( 100, 0.0, 100.0, opts );
98101

99-
for ( i = 0; i < 100; i++ ) {
100-
x = randu() * 10.0;
101-
console.log( 'y0(%d) = %d', x, y0( x ) );
102-
}
102+
logEachMap( 'bessely0(%0.4f) = %0.4f', x, bessely0 );
103103
```
104104

105105
</section>

lib/node_modules/@stdlib/math/base/special/bessely0/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var bessely0 = require( './../lib' );
2324

24-
var x;
25-
var i;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var x = uniform( 100, 0.0, 100.0, opts );
2629

27-
for ( i = 0; i < 100; i++ ) {
28-
x = randu() * 100.0;
29-
console.log( 'bessely0(%d) = %d', x, bessely0( x ) );
30-
}
30+
logEachMap( 'bessely0(%0.4f) = %0.4f', x, bessely0 );

lib/node_modules/@stdlib/math/base/special/bessely1/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ v = y1( NaN );
9191
<!-- eslint no-undef: "error" -->
9292

9393
```javascript
94-
var randu = require( '@stdlib/random/base/randu' );
95-
var y1 = require( '@stdlib/math/base/special/bessely1' );
94+
var uniform = require( '@stdlib/random/array/uniform' );
95+
var logEachMap = require( '@stdlib/console/log-each-map' );
96+
var bessely1 = require( '@stdlib/math/base/special/bessely1' );
9697

97-
var x;
98-
var i;
98+
var opts = {
99+
'dtype': 'float64'
100+
};
101+
var x = uniform( 100, 0.0, 100.0, opts );
99102

100-
for ( i = 0; i < 100; i++ ) {
101-
x = randu() * 10.0;
102-
console.log( 'y1(%d) = %d', x, y1( x ) );
103-
}
103+
logEachMap( 'bessely1(%0.4f) = %0.4f', x, bessely1 );
104104
```
105105

106106
</section>

lib/node_modules/@stdlib/math/base/special/bessely1/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var bessely1 = require( './../lib' );
2324

24-
var x;
25-
var i;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var x = uniform( 100, 0.0, 100.0, opts );
2629

27-
for ( i = 0; i < 100; i++ ) {
28-
x = randu() * 100.0;
29-
console.log( 'bessely1(%d) = %d', x, bessely1( x ) );
30-
}
30+
logEachMap( 'bessely1(%0.4f) = %0.4f', x, bessely1 );

lib/node_modules/@stdlib/math/base/special/betainc/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,18 @@ var y = betainc( 0.5, 2.0, -2.0 );
102102
<!-- eslint no-undef: "error" -->
103103

104104
```javascript
105-
var randu = require( '@stdlib/random/base/randu' );
105+
var uniform = require( '@stdlib/random/array/uniform' );
106+
var logEachMap = require( '@stdlib/console/log-each-map' );
106107
var betainc = require( '@stdlib/math/base/special/betainc' );
107108

108-
var i;
109-
var x;
110-
var a;
111-
var b;
112-
113-
for ( i = 0; i < 100; i++ ) {
114-
x = randu();
115-
a = randu() * 10.0;
116-
b = randu() * 10.0;
117-
console.log( 'x: %d, \t a: %d, \t b: %d, \t f(x,a,b): %d', x.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), betainc( x, a, b ).toFixed( 4 ) );
118-
}
109+
var opts = {
110+
'dtype': 'float64'
111+
};
112+
var x = uniform( 100, 0.0, 1.0, opts );
113+
var a = uniform( 100, 0.0, 10.0, opts );
114+
var b = uniform( 100, 0.0, 10.0, opts );
115+
116+
logEachMap( 'x: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(x,a,b): %0.4f', x, a, b, betainc );
119117
```
120118

121119
</section>

lib/node_modules/@stdlib/math/base/special/betainc/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var betainc = require( './../lib' );
2324

24-
var i;
25-
var x;
26-
var a;
27-
var b;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var x = uniform( 100, 0.0, 1.0, opts );
29+
var a = uniform( 100, 0.0, 10.0, opts );
30+
var b = uniform( 100, 0.0, 10.0, opts );
2831

29-
for ( i = 0; i < 100; i++ ) {
30-
x = randu();
31-
a = randu() * 10.0;
32-
b = randu() * 10.0;
33-
console.log( 'x: %d, \t a: %d, \t b: %d, \t f(x,a,b): %d', x.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), betainc( x, a, b ).toFixed( 4 ) );
34-
}
32+
logEachMap( 'x: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(x,a,b): %0.4f', x, a, b, betainc );

lib/node_modules/@stdlib/math/base/special/betaincinv/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,18 @@ y = betaincinv( 0.5, 2.0, 0.0 );
111111
<!-- eslint no-undef: "error" -->
112112

113113
```javascript
114-
var randu = require( '@stdlib/random/base/randu' );
114+
var uniform = require( '@stdlib/random/array/uniform' );
115+
var logEachMap = require( '@stdlib/console/log-each-map' );
115116
var betaincinv = require( '@stdlib/math/base/special/betaincinv' );
116117

117-
var i;
118-
var p;
119-
var a;
120-
var b;
121-
122-
for ( i = 0; i < 100; i++ ) {
123-
p = randu();
124-
a = randu() * 10.0;
125-
b = randu() * 10.0;
126-
console.log( 'p: %d, \t a: %d, \t b: %d, \t f(p,a,b): %d', p.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), betaincinv( p, a, b ) );
127-
}
118+
var opts = {
119+
'dtype': 'float64'
120+
};
121+
var p = uniform( 100, 0.0, 1.0, opts );
122+
var a = uniform( 100, 0.0, 10.0, opts );
123+
var b = uniform( 100, 0.0, 10.0, opts );
124+
125+
logEachMap( 'p: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(p,a,b): %0.4f', p, a, b, betaincinv );
128126
```
129127

130128
</section>

lib/node_modules/@stdlib/math/base/special/betaincinv/examples/index.js

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

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var betaincinv = require( './../lib' );
2324

24-
var i;
25-
var p;
26-
var a;
27-
var b;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var p = uniform( 100, 0.0, 1.0, opts );
29+
var a = uniform( 100, 0.0, 10.0, opts );
30+
var b = uniform( 100, 0.0, 10.0, opts );
2831

29-
for ( i = 0; i < 100; i++ ) {
30-
p = randu();
31-
a = randu() * 10.0;
32-
b = randu() * 10.0;
33-
console.log( 'p: %d, \t a: %d, \t b: %d, \t f(p,a,b): %d', p.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), betaincinv( p, a, b ) );
34-
}
32+
logEachMap( 'p: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(p,a,b): %0.4f', p, a, b, betaincinv );

lib/node_modules/@stdlib/math/base/special/binomcoef/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,17 @@ v = binomcoef( 5.5, 2 );
124124
<!-- eslint no-undef: "error" -->
125125

126126
```javascript
127-
var randu = require( '@stdlib/random/base/randu' );
128-
var round = require( '@stdlib/math/base/special/round' );
127+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
128+
var logEachMap = require( '@stdlib/console/log-each-map' );
129129
var binomcoef = require( '@stdlib/math/base/special/binomcoef' );
130130

131-
var n;
132-
var k;
133-
var i;
131+
var opts = {
132+
'dtype': 'float64'
133+
};
134+
var n = discreteUniform( 100, -10, 30, opts );
135+
var k = discreteUniform( 100, 0, 20, opts );
134136

135-
for ( i = 0; i < 100; i++ ) {
136-
n = round( (randu()*30.0) - 10.0 );
137-
k = round( randu()*20.0 );
138-
console.log( '%d choose %d = %d', n, k, binomcoef( n, k ) );
139-
}
137+
logEachMap( '%d choose %d = %d', n, k, binomcoef );
140138
```
141139

142140
</section>

lib/node_modules/@stdlib/math/base/special/binomcoef/examples/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var round = require( '@stdlib/math/base/special/round' );
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2323
var binomcoef = require( './../lib' );
2424

25-
var n;
26-
var k;
27-
var i;
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var n = discreteUniform( 100, -10, 30, opts );
29+
var k = discreteUniform( 100, 0, 20, opts );
2830

29-
for ( i = 0; i < 100; i++ ) {
30-
n = round( (randu()*40.0) - 10.0 );
31-
k = round( randu()*20.0 );
32-
console.log( '%d choose %d = %d', n, k, binomcoef( n, k ) );
33-
}
31+
logEachMap( '%d choose %d = %d', n, k, binomcoef );

lib/node_modules/@stdlib/math/base/special/binomcoefln/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,17 @@ v = binomcoefln( 5.5, 2 );
139139
<!-- eslint no-undef: "error" -->
140140

141141
```javascript
142-
var randu = require( '@stdlib/random/base/randu' );
143-
var round = require( '@stdlib/math/base/special/round' );
142+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
143+
var logEachMap = require( '@stdlib/console/log-each-map' );
144144
var binomcoefln = require( '@stdlib/math/base/special/binomcoefln' );
145145

146-
var n;
147-
var k;
148-
var i;
146+
var opts = {
147+
'dtype': 'float64'
148+
};
149+
var n = discreteUniform( 100, -10, 30, opts );
150+
var k = discreteUniform( 100, 0, 20, opts );
149151

150-
for ( i = 0; i < 100; i++ ) {
151-
n = round( (randu()*40.0) - 10.0 );
152-
k = round( randu()*20.0 );
153-
console.log( 'ln( %d choose %d ) = %d', n, k, binomcoefln( n, k ) );
154-
}
152+
logEachMap( 'ln( %d choose %d ) = %d', n, k, binomcoefln );
155153
```
156154

157155
</section>

0 commit comments

Comments
 (0)