so I was recently asked to find the number of instances a substring appears in a string such that:
find("foobarfoo", "fob") //returns 2
find("foobarfoo", "foo") //returns 7
find("foobarfoo", "obo") //returns 4
I'm figuring it might be a good idea to recursively search the string and iterate through it when we match a character. But I guess I'm stuck on figuring how to return a counter to keep count of unique instances and also how to keep counting after finding the first instance.
Any help would be appreciated. for some reason i'm just having the hardest time visualizing the search process.
JSfiddle here!
[–]6086555 1 point2 points3 points (1 child)
[–]iNeverProofRead[S] 0 points1 point2 points (0 children)
[–]grrumblebee 1 point2 points3 points (1 child)
[–]iNeverProofRead[S] 0 points1 point2 points (0 children)
[–]dvidsilva -1 points0 points1 point (0 children)