forEachCodePointRight
Invokes a function for each Unicode code point in a string, iterating from right to left.
Usage
var forEachCodePointRight = require( '@stdlib/string/base/for-each-code-point-right' );
forEachCodePointRight( str, clbk[, thisArg ] )
Invokes a function for each Unicode code point in a string, iterating from right to left.
function log( value, index ) {
console.log( '%d: %s', index, value );
}
forEachCodePointRight( 'Beep!', log );
/* =>
4: !
3: p
2: e
1: e
0: B
*/
The invoked function is provided three arguments:
- value: Unicode code point.
- index: starting Unicode code point index.
- str: input string.
To set the function execution context, provide a thisArg
.
function clbk() {
this.count += 1;
}
var str = '👉🏿';
var ctx = {
'count': 0
};
forEachCodePointRight( str, clbk, ctx );
var cnt = ctx.count;
// returns 2
Examples
var forEachCodePointRight = require( '@stdlib/string/base/for-each-code-point-right' );
function log( value, index ) {
console.log( '%d: %s', index, value );
}
forEachCodePointRight( 'presidential election', log );
forEachCodePointRight( 'Iñtërnâtiônàlizætiøn', log );
forEachCodePointRight( '🌷🍕', log );
forEachCodePointRight( '\uD834\uDD1E', log );