I myself found a bottle neck.
when i did it
for (i = string.length; i > 1; i--) {
I accidentally deleted "var" from var i
, so I made i
global. After the correction, I got the expected results.
for (var i = string.length; i > 1; i--) {
I never thought it could be a HUGE difference, so pay attention to the guys.
Benckmark test fixed here
Before
After:
PS: for practical use, DO NOT use these functions, the indexOf version is much faster.
source share