gap buffer data structure in Javascript programming language