Skip to content

Commit e61ced4

Browse files
committed
docs: update examples and copy
1 parent 6d01566 commit e61ced4

File tree

1 file changed

+17
-106
lines changed
  • lib/node_modules/@stdlib/string/for-each

1 file changed

+17
-106
lines changed

lib/node_modules/@stdlib/string/for-each/README.md

Lines changed: 17 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ var forEach = require( '@stdlib/string/for-each' );
4242

4343
#### forEach( str, clbk\[, thisArg ] )
4444

45-
Invokes a `function` for each (visual) character of a `string`.
45+
Invokes a function for each (visual) character of a string.
4646

4747
```javascript
4848
function log( value, index ) {
49-
console.log( '%s: %d', index, value );
49+
console.log( '%d: %s', index, value );
5050
}
5151

52-
var str = 'Hello World!';
53-
54-
forEach( str, log );
52+
forEach( 'Hello, world!', log );
5553
/* =>
5654
0: H
5755
1: e
@@ -68,76 +66,28 @@ forEach( str, log );
6866
*/
6967
```
7068

71-
The invoked `function` is provided three arguments:
72-
73-
- `value`: visual character.
74-
- `index`: starting character index.
75-
- `str`: input string.
76-
77-
```javascript
78-
function log1( value, index ) {
79-
var repeatVal = value + value;
80-
console.log( '%s: %d', index, repeatVal );
81-
}
69+
The invoked function is provided three arguments:
8270

83-
var str1 = 'Hello World!';
84-
85-
forEach( str1, log1 );
86-
/* =>
87-
0: HH
88-
1: ee
89-
2: ll
90-
3: ll
91-
4: oo
92-
5:
93-
6: WW
94-
7: oo
95-
8: rr
96-
9: ll
97-
10: dd
98-
11: !!
99-
*/
100-
101-
function log2( value, index ) {
102-
var upperCased = value.toUpperCase();
103-
console.log( '%s: %d', index, upperCased );
104-
}
105-
106-
var str2 = 'hello world!';
107-
108-
forEach( str2, log2 );
109-
/* =>
110-
0: H
111-
1: E
112-
2: L
113-
3: L
114-
4: O
115-
5:
116-
6: W
117-
7: O
118-
8: R
119-
9: L
120-
10: D
121-
11: !
122-
*/
123-
```
71+
- `value`: visual character
72+
- `index`: starting character index
73+
- `str`: input string
12474

12575
To set the function execution context, provide a `thisArg`.
12676

12777
```javascript
128-
function count( value ) {
78+
function clbk() {
12979
this.count += 1;
13080
}
13181

132-
var str3 = 'hello world!';
82+
var str = 'Hello, world!';
13383

134-
var context = {
84+
var ctx = {
13585
'count': 0
13686
};
13787

138-
forEach( str3, count, context );
88+
forEach( str, clbk, ctx );
13989

140-
var bool = str3.length === context.count;
90+
var bool = ( str.length === ctx.count );
14191
// returns true
14292
```
14393

@@ -149,27 +99,6 @@ var bool = str3.length === context.count;
14999

150100
<section class="notes">
151101

152-
## Notes
153-
154-
- The function differs from traditional string iterations in the following ways:
155-
156-
- The function returns the input `str`.
157-
158-
- The `clbk` is executed on each _visual_ character as opposed to being executed on each character.
159-
160-
```javascript
161-
function log( value, index ) {
162-
console.log( '%s: %s', index, value );
163-
}
164-
165-
var str = '\uD834\uDD1E';
166-
167-
forEach( str, log );
168-
/* =>
169-
0: 𝄞
170-
*/
171-
```
172-
173102
</section>
174103

175104
<!-- /.notes -->
@@ -183,19 +112,16 @@ var bool = str3.length === context.count;
183112
<!-- eslint no-undef: "error" -->
184113

185114
```javascript
186-
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
187115
var forEach = require( '@stdlib/string/for-each' );
188116

189117
function log( value, index ) {
190-
if ( isEven( index ) ) {
191-
console.log( '%s: %d', index, '*' );
192-
} else {
193-
console.log( '%s: %d', index, value );
194-
}
118+
console.log( '%d: %s', index, value );
195119
}
196120

197-
var str4 = 'Javascript';
198-
forEach( str4, log );
121+
forEach( 'presidential election', log );
122+
forEach( 'Iñtërnâtiônàlizætiøn', log );
123+
forEach( '🌷🍕', log );
124+
forEach( '\uD834\uDD1E', log );
199125
```
200126

201127
</section>
@@ -214,13 +140,6 @@ forEach( str4, log );
214140

215141
<section class="related">
216142

217-
* * *
218-
219-
## See Also
220-
221-
- <span class="package-name">[`@stdlib/utils/for-each`][@stdlib/utils/for-each]</span><span class="delimiter">: </span><span class="description">invoke a function once for each element in a collection.</span>
222-
- <span class="package-name">[`@stdlib/utils/async/for-each`][@stdlib/utils/async/for-each]</span><span class="delimiter">: </span><span class="description">invoke an async function once for each element in a collection.</span>
223-
224143
</section>
225144

226145
<!-- /.related -->
@@ -229,14 +148,6 @@ forEach( str4, log );
229148

230149
<section class="links">
231150

232-
<!-- <related-links> -->
233-
234-
[@stdlib/utils/for-each]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/for-each
235-
236-
[@stdlib/utils/async/for-each]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/for-each
237-
238-
<!-- </related-links> -->
239-
240151
</section>
241152

242153
<!-- /.links -->

0 commit comments

Comments
 (0)