Skip to content

Commit ad867de

Browse files
committed
string.js: started extracting functions into own modules; count() extracted
1 parent a96f140 commit ad867de

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/_count.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function count(self, substr) {
2+
var count = 0
3+
var pos = self.indexOf(substr)
4+
5+
while (pos >= 0) {
6+
count += 1
7+
pos = self.indexOf(substr, pos + 1)
8+
}
9+
10+
return count
11+
}
12+
13+
module.exports = count

lib/string.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,7 @@ string.js - Copyright (C) 2012-2014, JP Richardson <[email protected]>
121121
},
122122

123123
count: function(ss) {
124-
var count = 0
125-
, pos = this.s.indexOf(ss)
126-
127-
while (pos >= 0) {
128-
count += 1
129-
pos = this.s.indexOf(ss, pos + 1)
130-
}
131-
132-
return count
124+
return require('./_count')(this.s, ss)
133125
},
134126

135127
//#modified from https://github.com/epeli/underscore.string

0 commit comments

Comments
 (0)