Tuesday, April 17, 2012
While working on my favorite project I had to count the colons in a string. I was wondering which could be the best solution. I had two methods in my mind to solve that.
The first is the "split" method:
The other one is the "RegExp" method:
After googling for a while I found a test which one is better:
Well, that graph is self explanatory I guess :) (Thanks jsPerf.com)
In the mean time I stumbled into this solution which I think is quite interesting:
This is the code:
And this is the usage:
But because in my project I have to use a minimal amount of global footstep I sticked to the "RegExp" method.