Chalarangelo / 30-seconds-of-code

Short code snippets for all your development needs

Home Page:https://30secondsofcode.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New snipper

coralhayoun opened this issue · comments

Hi,
I've wnated to add a new snipper called countStringOccurrences, which counts the occurrences of a string in another string
for examle: 'tt' occurs twice at 'attbtt'
right now theres only countOccurrences of an item in an array
is it ok to add it?

Thanks for asking. countOccurences will work with strings if spread to arrays ([...str]), so it's pretty much the same snippet in reality, so we shouldn't add one more for strings.

spread it to array would help you find character occurences but not another string occurences

@coralhayoun Fair enough, String.prototype.search() orString.prototype.indexOf() in combination with String.prototype.split() will most likely do the trick then.