Super basic circular buffer implementation in JS