Skip to content

Commit 957a205

Browse files
anandkaranubckgryte
authored andcommitted
docs: add examples for string and float formatting
PR-URL: stdlib-js#6277 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent ca817ae commit 957a205

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

lib/node_modules/@stdlib/console/log-each-map/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# logEachMap
2222

23-
> Insert array element values and the result of a callback function into a format string and print the result.
23+
> Insert array element values and the result of a callback function into a [format string][@stdlib/string/format] and print the result.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var logEachMap = require( '@stdlib/console/log-each-map' );
4242

4343
#### logEachMap( str\[, ...args], clbk\[, thisArg] )
4444

45-
Inserts array element values and the result of a callback function into a format string and prints the result.
45+
Inserts array element values and the result of a callback function into a [format string][@stdlib/string/format] and prints the result.
4646

4747
```javascript
4848
function add( a, b ) {
@@ -95,10 +95,10 @@ function multiply( x, y ) {
9595
}
9696

9797
var x = [ 1, 2, 3 ];
98-
var y = 2;
98+
var y = 0.5;
9999

100-
logEachMap( '%d * %d = %d', x, y, multiply );
101-
// e.g., => '1 * 2 = 2\n2 * 2 = 4\n3 * 2 = 6\n'
100+
logEachMap( '%0.1f * %0.1f = %0.1f', x, y, multiply );
101+
// e.g., => '1.0 * 0.5 = 0.5\n2.0 * 0.5 = 1.0\n3.0 * 0.5 = 1.5\n'
102102
```
103103

104104
The callback function is provided the following arguments:
@@ -182,6 +182,8 @@ logEachMap( '%d + %d = %d', x, y, add );
182182

183183
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
184184

185+
[@stdlib/string/format]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format
186+
185187
</section>
186188

187189
<!-- /.links -->

lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,15 @@
2727
> function f( x, y ) { return x + y; };
2828
> {{alias}}( '%d + %d = %d', x, y, f );
2929

30+
> var x = [ 0.5, 1.0, 1.5 ];
31+
> var y = [ 0.5, 0.75, 1.0 ];
32+
> function f( x, y ) { return x * y; };
33+
> {{alias}}( '%0.2f * %0.2f = %0.2f', x, y, f );
34+
35+
> var x = [ 'foo', 'bar' ];
36+
> var y = [ 'baz', 'beep' ];
37+
> function f( x, y ) { return x + y; };
38+
> {{alias}}( '%s+%s = %s', x, y, f );
39+
3040
See Also
3141
--------

lib/node_modules/@stdlib/console/log-each-map/lib/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@
3535
*
3636
* logEachMap( '%d + %d = %d', x, y, add );
3737
* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
38+
*
39+
* function multiply( x, y ) {
40+
* return x * y;
41+
* }
42+
*
43+
* var x = [ 0.5, 1.0, 1.5 ];
44+
* var y = [ 0.5, 0.75, 1.0 ];
45+
*
46+
* logEachMap( '%0.2f * %0.2f = %0.2f', x, y, multiply );
47+
* // e.g., => '0.50 * 0.50 = 0.25\n1.00 * 0.75 = 0.75\n1.50 * 1.00 = 1.50\n'
48+
*
49+
* function append( x, y ) {
50+
* return x + y;
51+
* }
52+
*
53+
* var x = [ 'foo', 'bar' ];
54+
* var y = [ 'baz', 'beep' ];
55+
*
56+
* logEachMap( '%s+%s = %s', x, y, append );
57+
* // e.g., => 'foo+baz = foobaz\nbar+beep = barbeep\n'
3858
*/
3959

4060
// MODULES //

lib/node_modules/@stdlib/console/log-each-map/lib/main.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ var logger = require( '@stdlib/console/log' );
5454
*
5555
* logEachMap( '%d + %d = %d', x, y, add );
5656
* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
57+
*
58+
* @example
59+
* function multiply( x, y ) {
60+
* return x * y;
61+
* }
62+
*
63+
* var x = [ 0.5, 1.0, 1.5 ];
64+
* var y = [ 0.5, 0.75, 1.0 ];
65+
*
66+
* logEachMap( '%0.2f * %0.2f = %0.2f', x, y, multiply );
67+
* // e.g., => '0.50 * 0.50 = 0.25\n1.00 * 0.75 = 0.75\n1.50 * 1.00 = 1.50\n'
68+
*
69+
* @example
70+
* function append( x, y ) {
71+
* return x + y;
72+
* }
73+
*
74+
* var x = [ 'foo', 'bar' ];
75+
* var y = [ 'baz', 'beep' ];
76+
*
77+
* logEachMap( '%s+%s = %s', x, y, append );
78+
* // e.g., => 'foo+baz = foobaz\nbar+beep = barbeep\n'
5779
*/
5880
function logEachMap( str ) {
5981
var strides;

0 commit comments

Comments
 (0)