Skip to content

Commit cc611d0

Browse files
docs: add examples for string and float formatting
PR-URL: #6325 Reviewed-by: Athan Reines <[email protected]>
1 parent 235d042 commit cc611d0

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# logEach
2222

23-
> Insert array element values into a format string and print the result.
23+
> Insert array element values 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 logEach = require( '@stdlib/console/log-each' );
4242

4343
#### logEach( str\[, ...args] )
4444

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

4747
```javascript
4848
var x = [ 1, 2, 3 ];
@@ -56,10 +56,10 @@ If an interpolated argument is not an array-like object, the argument is broadca
5656

5757
```javascript
5858
var x = [ 1, 2, 3 ];
59-
var y = 4;
59+
var y = 0.5;
6060

61-
logEach( '%d < %d', x, y );
62-
// e.g., => '1 < 4\n2 < 4\n3 < 4\n'
61+
logEach( '%0.1f > %0.1f', x, y );
62+
// e.g., => '1.0 > 0.5\n2.0 > 0.5\n3.0 > 0.5\n'
6363
```
6464

6565
</section>
@@ -130,6 +130,8 @@ logEach( 'abs(%d) = %d', x, y );
130130

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

133+
[@stdlib/string/format]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format
134+
133135
</section>
134136

135137
<!-- /.links -->

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

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
> var y = [ 4, 5, 6 ];
2020
> {{alias}}( '%d < %d ', x, y );
2121

22+
> var x = [ 0.5, 1.0, 1.5 ];
23+
> var y = [ 0.25, 0.5, 0.75 ];
24+
> {{alias}}( '%0.2f > %0.2f', x, y );
25+
26+
> var x = [ 'foo', 'bar' ];
27+
> var y = [ 'beep', 'boop' ];
28+
> {{alias}}( 'x: %s, y: %s', x, y );
29+
2230
See Also
2331
--------
2432

lib/node_modules/@stdlib/console/log-each/docs/types/index.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@
3535
*
3636
* logEach( '%d < %d ', x, y );
3737
* // e.g., => '1 < 4\n2 < 5\n3 < 6\n'
38+
*
39+
* @example
40+
* var x = [ 0.5, 1.0, 1.5 ];
41+
* var y = [ 0.25, 0.5, 0.75 ];
42+
*
43+
* logEach( '%0.2f > %0.2f', x, y );
44+
* // e.g., => '0.50 > 0.25\n1.00 > 0.50\n1.50 > 0.75\n'
45+
*
46+
* @example
47+
* var x = [ 'foo', 'bar' ];
48+
* var y = [ 'beep', 'boop' ];
49+
*
50+
* logEach( 'x: %s, y: %s', x, y );
51+
* // e.g., => 'x: foo, y: beep\nx: bar, y: boop\n'
3852
*/
3953
declare function logEach( str: string, ...args: any ): void;
4054

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

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
*
3232
* logEach( '%d < %d ', x, y );
3333
* // e.g., => '1 < 4\n2 < 5\n3 < 6\n'
34+
*
35+
* var x = [ 0.5, 1.0, 1.5 ];
36+
* var y = [ 0.25, 0.5, 0.75 ];
37+
*
38+
* logEach( '%0.2f > %0.2f', x, y );
39+
* // e.g., => '0.50 > 0.25\n1.00 > 0.50\n1.50 > 0.75\n'
40+
*
41+
* var x = [ 'foo', 'bar' ];
42+
* var y = [ 'beep', 'boop' ];
43+
*
44+
* logEach( 'x: %s, y: %s', x, y );
45+
* // e.g., => 'x: foo, y: beep\nx: bar, y: boop\n'
3446
*/
3547

3648
// MODULES //

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

+21
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ var logger = require( '@stdlib/console/log' );
3737
* @throws {TypeError} first argument must be a string
3838
* @throws {RangeError} provided collections must have the same length
3939
* @returns {void}
40+
*
41+
* @example
42+
* var x = [ 1, 2, 3 ];
43+
* var y = [ 4, 5, 6 ];
44+
*
45+
* logEach( '%d < %d ', x, y );
46+
* // e.g., => '1 < 4\n2 < 5\n3 < 6\n'
47+
*
48+
* @example
49+
* var x = [ 0.5, 1.0, 1.5 ];
50+
* var y = [ 0.25, 0.5, 0.75 ];
51+
*
52+
* logEach( '%0.2f > %0.2f', x, y );
53+
* // e.g., => '0.50 > 0.25\n1.00 > 0.50\n1.50 > 0.75\n'
54+
*
55+
* @example
56+
* var x = [ 'foo', 'bar' ];
57+
* var y = [ 'beep', 'boop' ];
58+
*
59+
* logEach( 'x: %s, y: %s', x, y );
60+
* // e.g., => 'x: foo, y: beep\nx: bar, y: boop\n'
4061
*/
4162
function logEach( str ) {
4263
var strides;

0 commit comments

Comments
 (0)