Skip to content

docs: add examples for string and float formatting #6277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/node_modules/@stdlib/console/log-each-map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# logEachMap

> Insert array element values and the result of a callback function into a format string and print the result.
> Insert array element values and the result of a callback function into a [format string][@stdlib/string/format] and print the result.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

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

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

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

```javascript
function add( a, b ) {
Expand Down Expand Up @@ -95,10 +95,10 @@ function multiply( x, y ) {
}

var x = [ 1, 2, 3 ];
var y = 2;
var y = 0.5;

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

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

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

[@stdlib/string/format]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format

</section>

<!-- /.links -->
10 changes: 10 additions & 0 deletions lib/node_modules/@stdlib/console/log-each-map/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@
> function f( x, y ) { return x + y; };
> {{alias}}( '%d + %d = %d', x, y, f );

> var x = [ 0.5, 1.0, 1.5 ];
> var y = [ 0.5, 0.75, 1.0 ];
> function f( x, y ) { return x * y; };
> {{alias}}( '%0.2f * %0.2f = %0.2f', x, y, f );

> var x = [ 'foo', 'bar' ];
> var y = [ 'baz', 'beep' ];
> function f( x, y ) { return x + y; };
> {{alias}}( '%s+%s = %s', x, y, f );

See Also
--------
20 changes: 20 additions & 0 deletions lib/node_modules/@stdlib/console/log-each-map/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@
*
* logEachMap( '%d + %d = %d', x, y, add );
* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
*
* function multiply( x, y ) {
* return x * y;
* }
*
* var x = [ 0.5, 1.0, 1.5 ];
* var y = [ 0.5, 0.75, 1.0 ];
*
* logEachMap( '%0.2f * %0.2f = %0.2f', x, y, multiply );
* // e.g., => '0.50 * 0.50 = 0.25\n1.00 * 0.75 = 0.75\n1.50 * 1.00 = 1.50\n'
*
* function append( x, y ) {
* return x + y;
* }
*
* var x = [ 'foo', 'bar' ];
* var y = [ 'baz', 'beep' ];
*
* logEachMap( '%s+%s = %s', x, y, append );
* // e.g., => 'foo+baz = foobaz\nbar+beep = barbeep\n'
*/

// MODULES //
Expand Down
22 changes: 22 additions & 0 deletions lib/node_modules/@stdlib/console/log-each-map/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ var logger = require( '@stdlib/console/log' );
*
* logEachMap( '%d + %d = %d', x, y, add );
* // e.g., => '1 + 4 = 5\n2 + 5 = 7\n3 + 6 = 9\n'
*
* @example
* function multiply( x, y ) {
* return x * y;
* }
*
* var x = [ 0.5, 1.0, 1.5 ];
* var y = [ 0.5, 0.75, 1.0 ];
*
* logEachMap( '%0.2f * %0.2f = %0.2f', x, y, multiply );
* // e.g., => '0.50 * 0.50 = 0.25\n1.00 * 0.75 = 0.75\n1.50 * 1.00 = 1.50\n'
*
* @example
* function append( x, y ) {
* return x + y;
* }
*
* var x = [ 'foo', 'bar' ];
* var y = [ 'baz', 'beep' ];
*
* logEachMap( '%s+%s = %s', x, y, append );
* // e.g., => 'foo+baz = foobaz\nbar+beep = barbeep\n'
*/
function logEachMap( str ) {
var strides;
Expand Down