Skip to content

Commit

Permalink
refactor: simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jul 14, 2023
1 parent e15e962 commit 0b65262
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions lib/node_modules/@stdlib/string/base/first/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,7 @@
* // returns 'H'
*/
function first( str, n ) {
var out;
var cnt;
var i;
if ( str === '' || n === 0 ) {
return '';
}
if ( n === 1 ) {
return str[ 0 ];
}
out = '';
cnt = 0;
for ( i = 0; i < str.length; i++ ) {
out += str[ i ];
cnt += 1;
if ( cnt === n ) {
break;
}
}
return out;
return str.substring( 0, n );
}


Expand Down

0 comments on commit 0b65262

Please sign in to comment.