JavaScript Circular Buffer