Porting RDSE to JavaScript

I’m running into a problem porting the RDSE from python to JavaScript. Looking for help understanding why my _createBuckets function is recursively diving into negative indices:

https://github.com/htm-community/sdr-viz/blob/master/js/lib/encoders.js#L164-L191

You can see this in action live at http://htm-community.github.io/sdr-viz/site/rdse.html (your browser might hang because _createBucket is a recursive function and blows the call stack. But if you open up a web inspector, you should see the following dump to the console:

Adding additional buckets to handle index=500
encoders.js:167 createBucket(500) (should not be negative)
encoders.js:167 createBucket(499) (should not be negative)
encoders.js:167 createBucket(500) (should not be negative)
encoders.js:167 createBucket(499) (should not be negative)
encoders.js:167 createBucket(498) (should not be negative)
encoders.js:167 createBucket(499) (should not be negative)
...
encoders.js:167 createBucket(4) (should not be negative)
encoders.js:167 createBucket(3) (should not be negative)
encoders.js:167 createBucket(2) (should not be negative)
encoders.js:167 createBucket(3) (should not be negative)
encoders.js:167 createBucket(2) (should not be negative)
encoders.js:167 createBucket(1) (should not be negative)
encoders.js:167 createBucket(2) (should not be negative)
encoders.js:167 createBucket(1) (should not be negative)
encoders.js:167 createBucket(0) (should not be negative)
encoders.js:167 createBucket(1) (should not be negative)
encoders.js:167 createBucket(0) (should not be negative)
encoders.js:167 createBucket(-1) (should not be negative)
encoders.js:167 createBucket(0) (should not be negative)
encoders.js:167 createBucket(-1) (should not be negative)
encoders.js:167 createBucket(-2) (should not be negative)
encoders.js:167 createBucket(-1) (should not be negative)
encoders.js:167 createBucket(-2) (should not be negative)

… eventually leading to a RangeError: Maximum call stack size exceeded exception.

From the docs in RDSE:

The "as long as they don’t become negative" part seems pretty important. I assume this is related to my bug. But I don’t see any check in the python RDSE to prevent negative indices. Can anyone help me understand what I’ve done wrong?

I found my problem, it was completely unrelated to the recursive function above:

The lodash library I’m using was returning all string keys from an object when calling .keys() on it, even if the keys were not actually strings.