copied Javascript version of code into SeriesIndexTokenizer.groovy