Count occurrences of a substring: Difference between revisions

m
J: reorder arguments to match task requirement
(J)
m (J: reorder arguments to match task requirement)
Line 105:
 
<lang j>require'strings'
countss=: #@[] %~ #@][ - ][ #@rplc '';~[]</lang>
 
In other words: find length of original string, replace the string to be counted with the empty string, find the difference in lengths and divide by the length of the string to be counted.
Line 111:
Example use:
 
<lang j> 'th' countss 'the three truths' countss 'th'
3
'ababababababab' countss 'ababababababab'
2</lang>
 
6,962

edits