Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 26, 2020
1 parent ccedfab commit e22da9e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
module.exports = ccount

function ccount(value, character) {
var val = String(value)
var count = 0
var index

value = String(value)

if (typeof character !== 'string' || character.length !== 1) {
throw new Error('Expected character')
}

index = value.indexOf(character)
index = val.indexOf(character)

while (index !== -1) {
count++
index = value.indexOf(character, index + 1)
index = val.indexOf(character, index + 1)
}

return count
Expand Down

0 comments on commit e22da9e

Please sign in to comment.