Skip to content

Commit 66e6314

Browse files
committed
Avoid for-in loop
1 parent 6421688 commit 66e6314

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/node_modules/@stdlib/nlp/expand-contractions/lib/expand_contractions.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var objectKeys = require( 'object-keys' ).shim();
2324
var isCapitalized = require( '@stdlib/assert/is-capitalized' );
2425
var uncapitalize = require( '@stdlib/string/uncapitalize' );
2526
var capitalize = require( '@stdlib/string/capitalize' );
@@ -28,6 +29,11 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2829
var CONTRACTIONS = require( './contractions.json' );
2930

3031

32+
// VARIABLES //
33+
34+
var KEYS = objectKeys( CONTRACTIONS );
35+
36+
3137
// MAIN //
3238

3339
/**
@@ -53,6 +59,8 @@ function expandContractions( str ) {
5359
var out;
5460
var key;
5561
var i;
62+
var j;
63+
5664
if ( !isString( str ) ) {
5765
throw new TypeError( 'invalid input argument. Must provide a primitive string. Value: `'+str+'`.' );
5866
}
@@ -61,14 +69,16 @@ function expandContractions( str ) {
6169
for ( i = 0; i < tokens.length; i++ ) {
6270
token = tokens[ i ];
6371
if ( isCapitalized( token ) ) {
64-
for ( key in CONTRACTIONS ) {
72+
for ( j = 0; j < KEYS.length; j++ ) {
73+
key = KEYS[ j ];
6574
if ( uncapitalize( token ) === key ) {
6675
token = capitalize( CONTRACTIONS[ key ] );
6776
break;
6877
}
6978
}
7079
} else {
71-
for ( key in CONTRACTIONS ) {
80+
for ( j = 0; j < KEYS.length; j++ ) {
81+
key = KEYS[ j ];
7282
if ( token === key ) {
7383
token = CONTRACTIONS[ key ];
7484
break;

0 commit comments

Comments
 (0)