Skip to content

Commit

Permalink
Merge pull request #421 from cartersgenes/patch-1
Browse files Browse the repository at this point in the history
Updated function with fastest implementation
  • Loading branch information
stoeffel committed May 6, 2015
2 parents 0fed8f6 + c721bbf commit d09c310
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions count.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ module.exports = function(str, substr) {
substr = makeString(substr);

if (str.length === 0 || substr.length === 0) return 0;

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

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

return count;

return str.split(substr).length - 1;
};

0 comments on commit d09c310

Please sign in to comment.