Skip to content

Commit cdc1523

Browse files
committed
docs: update examples and remove comments
1 parent e61ced4 commit cdc1523

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

lib/node_modules/@stdlib/string/for-each/lib/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
* @example
2727
* var forEach = require( '@stdlib/string/for-each' );
2828
*
29-
* function log( value, index, str ) {
30-
* console.log( '%s: %d', index, value );
29+
* function log( value, index ) {
30+
* console.log( '%d: %s', index, value );
3131
* }
3232
*
33-
* var str = 'presidential election';
34-
*
35-
* forEach( str, log );
33+
* forEach( 'Hello', log );
3634
*/
3735

3836
// MODULES //

lib/node_modules/@stdlib/string/for-each/lib/main.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@ var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-br
3434
* @param {string} str - input string
3535
* @param {Function} clbk - function to invoke
3636
* @param {*} [thisArg] - execution context
37-
* @throws {TypeError} first argument must be a string primitive
37+
* @throws {TypeError} first argument must be a string
3838
* @throws {TypeError} second argument must be a function
3939
* @returns {string} input string
4040
*
4141
* @example
42-
* function log( value, index, str ) {
43-
* console.log( '%s: %d', index, value );
42+
* function log( value, index ) {
43+
* console.log( '%d: %s', index, value );
4444
* }
4545
*
46-
* var str = 'Hello';
47-
*
48-
* forEach( str, log );
46+
* forEach( 'Hello', log );
4947
*/
5048
function forEach( str, clbk, thisArg ) {
5149
var len;
@@ -57,25 +55,14 @@ function forEach( str, clbk, thisArg ) {
5755
if ( !isFunction( clbk ) ) {
5856
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) );
5957
}
60-
if ( str === '' ) {
61-
return '';
62-
}
63-
64-
idx = 0;
6558
len = str.length;
59+
idx = 0;
6660
while ( idx < len ) {
67-
// Find out where the next grapheme cluster begins:
6861
brk = nextGraphemeClusterBreak( str, idx );
69-
70-
// -1 only when end of string is reached...
71-
if (brk === -1) {
62+
if ( brk === -1 ) {
7263
brk = len;
7364
}
74-
75-
// Invoke the clbk on the cluster:
76-
clbk.call( thisArg, str.substring(idx, brk), idx, str );
77-
78-
// Hop onto the beginning of the next cluster:
65+
clbk.call( thisArg, str.substring( idx, brk ), idx, str );
7966
idx = brk;
8067
}
8168
return str;

0 commit comments

Comments
 (0)