Skip to content

Commit

Permalink
Small codestyle changes for count method
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Oct 16, 2012
1 parent f7caf43 commit bb9eefa
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/underscore.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,19 @@

str = String(str);
substr = String(substr);
var n = 0;
var pos = 0;
var l = substr.length;

var count = 0,
pos = 0,
length = substr.length;

while (true) {
pos = str.indexOf(substr, pos);
if (pos !== -1) {
n++;
pos += l;
} else {
break;
}
if (pos === -1) break;
count++;
pos += length;
}
return n;

return count;
},

chars: function(str) {
Expand Down

0 comments on commit bb9eefa

Please sign in to comment.